Binding listbox maxHeight to parent actual - c#

So I am having some trouble getting the binding of a lisbox height to work. I have a user control that holds a listbox, this box is dynamically populated on the fly but it seems that if too many items are added it extends past the boundaries of the parent objects and refuses to stop and use the scoll bar...
<UserControl x:Class="TransaltionModule.Views.NoteView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d">
<Grid>
<ListBox ItemsSource="{Binding noteList}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Auto" >
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="1*"/>
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="5*"/>
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Grid.Column="0">
<TextBlock Text="Type :" VerticalAlignment="Center" FontSize="14" Width="65"/>
<TextBox Text="{Binding noteType}" Width="auto" IsEnabled="False" VerticalAlignment="Center" FontSize="14"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Column="1" HorizontalAlignment="Right">
<TextBlock Text="Date :" VerticalAlignment="Center" FontSize="14" Width="65"/>
<TextBox Text="{Binding timeStamp}" Width="auto" IsEnabled="False" VerticalAlignment="Center" FontSize="14"/>
</StackPanel>
<TextBlock Grid.Row="1" Text="{Binding text}" Grid.ColumnSpan="2"/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
If i hardcode the maxheight property everything works as intended, but with the multiple display resolutions I will be working against that is not a solution I can use. Can anyone recommend a fix

You can bind it to an element by using Path=ActualHeight
For this to work don't forget to name the Grid containing the Listbox
Try something like this :
<Grid x:Name = "grdListBoxTest">
<ListBox x:Name="lstBoxTest"
MaxHeight="{Binding ElementName=grdListBoxTest, Path=ActualHeight}">
<!-- Your Listbox Stuff Here -->
</ListBox>
</Grid>
By doing this you link the height of the Listbox to it's parent Grid. That way if the grid's size changes the MaxHeight of the Listbox will change.

Related

vertical scrollviewer bug in windows phone 8.1 c#

I have a page with lots of data so I need to use scrollviwer because of overflow items.
In this page I have something like list view (I made that) that has lots of items so I need to use scrollviewer for this list too.
So I have 2 vertical scrollviewer:
1) for all page items.
2) for My list view.
I made this app for windows phone 8.1. When I want to scroll in my list view I cant because of all page scrollviewer.
How can I solve that?
My code:
<ScrollViewer x:Name="ScrollViewerAllPage" Grid.Row="1" Grid.Column="0" Background="White" HorizontalScrollBarVisibility="Visible" ZoomMode="Disabled">
<Grid>
<StackPanel x:Name="StackMain" Orientation="Horizontal" Visibility="Collapsed">
...
<ScrollViewer x:Name="ScrollViewerReport" ScrollViewer.VerticalScrollMode="Enabled" Margin="32,0" Background="White" VerticalScrollBarVisibility="Visible" ZoomMode="Disabled" PointerPressed="ScrollViewerReport_PointerPressed">
<Grid x:Name="StackPanelReport" ScrollViewer.VerticalScrollBarVisibility="Visible" Margin="10,0" HorizontalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="70"/>
<ColumnDefinition Width="70" />
<ColumnDefinition Width="75" />
<ColumnDefinition Width="70" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" Orientation = "Vertical">
...
</StackPanel>
</StackPanel>
<StackPanel Grid.Column="1" Orientation = "Vertical">
...
</StackPanel>
</StackPanel>
<StackPanel Grid.Column="2" Orientation = "Vertical">
...
</StackPanel>
</StackPanel>
<StackPanel Grid.Column="3" Orientation = "Vertical">
...
</StackPanel>
</Grid>
</ScrollViewer>
</StackPanel>
</Grid>
I am sorry for bad English.
Thanks.

Array of custom Controls in WPF

I need to create Listbox in C#/WPF which contains the following
Something which is like a multi column list box,
One field for text, second field contains text which is to be chosen from a Combo Box.
I need to know the selection event so that I can validate the selection.
I am making a kind of mapping between two texts and the first field of text is not selectable, the second field to be selected from the combobox.
I need to put it in a box which is scrollable.
So my questions are
Is it possible to build such a thing using C#/WPF.
How do I trigger a window containing a listbox and capturing the selected item.
Lets Say
I have a signal A1, A2, A3
I need to map them to signal B1, B2, B3
So I want to show two rows of text
I want to get which signal got selected and then assign it to the correct row.
[edit]
Ok So I think it is possible to build one, I tried something with the following XAML code,
But I could not get the listbox to resize correctly and the data binding is still not Ok. Need to capture the Combobox selection too. :D
<Grid>
<ListBox Name="Mapping" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,5,0,0"
ItemsSource="{Binding Source=StaticResource CanMainPageViewModel.MappingInformation}"
>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Path=CanMainPageViewModel.MappingInformation.SigName}" Grid.Column="0" MinWidth="200" VerticalAlignment="Top" HorizontalAlignment="Stretch" FontSize="8"/>
<ComboBox Grid.Column="1" MinWidth="200" VerticalAlignment="Top" HorizontalAlignment="Stretch" FontSize="8"/>
</Grid>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
So my problem still remains,
[EDIT]
So playing around I found this can solve my problems now
<UserControl x:Class="Caribou_wpf.Controls.CanMostSignalMappingControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:controls="clr-namespace:Caribou_wpf.Controls"
xmlns:CanMainPageViewModel="clr-
namespace:Caribou_ViewModel.Data.CAN;assembly=Caribou_ViewModel"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
<DataTemplate x:Key="MappingInfoTemplate">
</DataTemplate>
</UserControl.Resources>
<Grid>
<ListBox Name="Mapping" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" Margin="0,5,0,0"
ItemsSource="{Binding CanMainPageViewModel.MappingInformation.Signals}"
>
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Path=CanSignal.SigName}"
Grid.Column="0" MinWidth="200" VerticalAlignment="Top"
HorizontalAlignment="Left" FontSize="10"/>
<ComboBox Grid.Column="1" MinWidth="200"
VerticalAlignment="Top" HorizontalAlignment="Right" FontSize="10"
ItemsSource="{Binding Path=MostPropertyParam}"
DisplayMemberPath="Name"
/>
</Grid>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</UserControl>
I just need to make sure that all items are ReadOnlyCollection
But somehow the controls are always sticking to the left. Can anyone point out please , why it is so.
Now how do I capture which object index is triggering the selected item in the combobox?
Thanks a lot.
Here is how I did it
<ListBox Name="Mapping" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="0,5,0,0"
ItemsSource="{Binding CanMainPageViewModel.MappingInformation.Signals}"
BorderThickness="1"
>
<ListBox.ItemTemplate >
<DataTemplate>
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Path=CanSignal.CompleteSignalName}" Grid.Column="0" MinWidth="280" FontSize="11" FontFamily="Calibri"
HorizontalAlignment="Stretch" TextAlignment="Right" Margin="5,2,3,2"/>
<ComboBox Grid.Column="1" MinWidth="280" FontSize="11" FontFamily="Calibri"
ItemsSource="{Binding Path=MostPropertyParameters}"
DisplayMemberPath="ParCompleteParamName" HorizontalContentAlignment="Stretch" Margin="3,2,5,2"
SelectedIndex="{Binding Path=SelectedMostPropertyParamIndex, Mode=TwoWay}"
/>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>

ItemsControl ScrollViewer return to initial position after scrolling

I am adding a ScrollViewer to ItemsControl whose ItemTemplate is generated dynamically.
The problem is the ScrollViewersnaps back to its initial position after scrolling. I tried setting the grid container Grid.Row="1" in which the ScrollViewer lies so that it has enough height or set it auto but the problem persist. What am I missing?
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel Grid.Row="0" Margin="12,17,0,28">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding GameLevel, Converter={StaticResource EnumToStringConverter}}" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock HorizontalAlignment="Right" Grid.Column="1" Style="{StaticResource PhoneTextNormalStyle}">
<Run Text="GAME "/>
<Run Text="{Binding CurrentGame}"/>
<Run Text=" / "/>
<Run Text="{Binding TotalGame}"/>
</TextBlock>
</Grid>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle2Style}">
<Run Text="{Binding CurrentTime, Converter={StaticResource SecondsToMinutesHour}}"/>
</TextBlock>
<TextBlock Foreground="Green" HorizontalAlignment="Right" Grid.Column="1" Margin="9,-7,9,0" Style="{StaticResource PhoneTextTitle2Style}">
<Run Text="{Binding TotalTime, Converter={StaticResource SecondsToMinutesHour}}"/>
</TextBlock>
<ProgressBar Grid.Row="1" Grid.ColumnSpan="2" x:Name="ProgressBar" Value="{Binding ProgressBarTime}" Minimum="0" Maximum="100" VerticalAlignment="Top" CacheMode="BitmapCache"/>
</Grid>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<ScrollViewer>
<ItemsControl x:Name="itemsControl" ItemsSource="{Binding Tiles}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Tag="{Binding Index}" Loaded="FrameworkElement_OnLoaded">
<Button Width="{Binding Side}"
Height="{Binding Side}"
Background="{Binding BgColor}"
Tag="{Binding Index}"
Content="{Binding Index}"
FontSize="{StaticResource PhoneFontSizeSmall}"
Click="Button_Click">
<ia:Interaction.Triggers>
<ia:EventTrigger EventName="Loaded">
<tr:SetCanvasPropertiesAction Left="{Binding Left}" Top="{Binding Top}" />
</ia:EventTrigger>
</ia:Interaction.Triggers>
</Button>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
</Grid>
<Grid x:Name="adGrid" Grid.Row="2" HorizontalAlignment="Center"/>
</Grid>
edit:
Ok, the real problem is, that the ItemsPnaelTemplate is a Canvas. The canvas always has Height=0 and Width=0. Items that are placed in the canvas can be bigger, but are still inside the canvas. The scrollviewer only has the Height of the canvas as an idea on how much it should be able to scroll.
You can easily test this by temporarily setting the height of the canvas:
<ItemsPanelTemplate>
<Canvas Height="1500"/>
</ItemsPanelTemplate>
And you will see, that now you can scroll.
Unfortunately I can't think of a solution right now. (Maybe setting the width and height of the itemsControl through code behind by calculating the needed width and height to dispay all items, by taking the items with the highest value for (Top + Side) as Height and (Left + Side) for Width)
original:
Your ContentPanel Grid has this Height="Auto". So the ContentPanel is the same Height as the ScrollViewer and all of it's content and the actual scrolling that you can still do is just the bouncing effect of the ScrollViewer when you get to the end of it's scrolling ability.
Just delete Height="Auto" and you should be fine.

Parent control ScrollViewer scrolling instead of child control ScrollViewer

I have this:
<Window x:Class="ScrollTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
Height="450"
Width="525">
<ScrollViewer ScrollViewer.HorizontalScrollBarVisibility="Visible"
ScrollViewer.VerticalScrollBarVisibility="Visible">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<GroupBox Grid.Row="0"
Header="Stuff"
Height="200">
<TextBlock Text="Lots of controls go here"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</GroupBox>
<TabControl Grid.Row="1">
<TabItem Header="Main Tab">
<TextBox MinHeight="100"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Left"
VerticalContentAlignment="Top"
ScrollViewer.HorizontalScrollBarVisibility="Visible"
ScrollViewer.VerticalScrollBarVisibility="Visible"
AcceptsReturn="True" />
</TabItem>
</TabControl>
</Grid>
</ScrollViewer>
</Window>
When I add too many rows into the TextBox, instead of the ScrollViewer of the TextBox being used, the box stretches and the outermost ScrollViewer is used. Can I prevent that without fixing the height of the TextBox or TabControl?
Update:
If I remove MinHeight on the TextBox and set MaxLines to 5, this is what I get:
If I added a 6th line, the scroll bars of the TextBox's ScrollViewer are used, but they still remain centered vertically in the TextBox control.
I was able to get close with this:
<Window x:Class="ScrollTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow"
Width="525">
<ScrollViewer ScrollViewer.VerticalScrollBarVisibility="Visible"
x:Name="Base">
<Grid Height="{Binding ElementName=Base, Path=ActualHeight, Mode=OneWay}"
MinHeight="400">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<GroupBox Grid.Row="0"
Header="Stuff"
Height="200">
<TextBlock Text="Lots of controls go here"
HorizontalAlignment="Center"
VerticalAlignment="Center" />
</GroupBox>
<TabControl Grid.Row="1">
<TabItem Header="Main Tab">
<Grid x:Name="myInnerGrid">
<TextBox MinHeight="100"
MaxHeight="{Binding ElementName=myInnerGrid, Path=ActualHeight, Mode=OneWay}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Left"
VerticalContentAlignment="Top"
ScrollViewer.HorizontalScrollBarVisibility="Visible"
ScrollViewer.VerticalScrollBarVisibility="Visible"
AcceptsReturn="True" />
</Grid>
</TabItem>
</TabControl>
</Grid>
</ScrollViewer>
</Window>
Note the binding expression on height for the outside grid and on MaxHeight for the TextBox.
It's still not perfect in that you have to manually set the MinHeight that will trigger the outer most scrollbar. It's probably as close as WPF will allow without writing a new grid control.
The idea was found here:
http://social.msdn.microsoft.com/Forums/en/wpf/thread/7b4b0c88-6b8f-4f07-aa8b-8e7018762388
Try looking at the MaxLines and MinLines Properties.
From above link:
Setting this property causes the text box to resize if the number of
visible lines exceeds the limit specified by MaxLines. This property
applies only to visible lines, and does not constrain the actual
number of lines. Depending on its configuration, a text box may
contain additional non-visible lines that are accessible by scrolling.
If the Height property is explicitly set on a TextBox, the MaxLines
and MinLines property values are ignored.
Try Changing:
<TextBox MinHeight="100"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
...
to
<TextBox MinLines="5"
MaxLines="5"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Edit: Give this a try. It is setting the VerticalContentAlignment of the TabItem. This will keep the text box at the top of the Tab, I also set the maxlines to what your available area is able to hold if you resize your form you may want to adjust that number to use all of the available space.
<TabItem Header="Main Tab" VerticalContentAlignment="Top" >
<TextBox
ScrollViewer.HorizontalScrollBarVisibility="Visible"
ScrollViewer.VerticalScrollBarVisibility="Visible"
MinLines="8"
MaxLines="8"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
HorizontalContentAlignment="Stretch"
VerticalContentAlignment="Stretch"
AcceptsReturn="True" />
</TabItem>
Edit:
After looking into it further, the reason the scrollbars are not showing up on the TextBox is because the TabControl and the TabItem are resizing to the size of the TextBox. What needs to be done is to have a limiting height set either on the TabControl, TabItem or TextBox this will allow the ScrollViewer to work for the TextBox.
I found that the best solution to this is to use the Border trick outlined here, applied both vertically and horizontally.
In the following example, a ScrollViewer contains a TextBox, where it is desired to have the TextBox fit all of the available space (vertically and horizontally), and have it scroll vertically before the parent ScrollViewer. The Border PlaceHolderBorder manages the Width of the TextBoxes as the parent window is resized. The Border DescriptionPlaceHolderBorder manages the Height of the Description TextBox as the parent control is resized, and the ScrollViewer of the TextBox kicks in before the parent control.
It is important to have Margins in the placeholder Borders.
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" Background="{StaticResource ControlBackgroundBrush}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="10"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="1" Grid.ColumnSpan="2" Style="{DynamicResource LabelHeader}" Content="Company" />
<Label Grid.Row="1" Grid.Column="1" Style="{DynamicResource CompanyNameInput}" Content="{Binding CompanyNameLabel}" />
<Label Grid.Row="2" Grid.Column="1" Style="{DynamicResource DescriptionInput}" Content="{Binding DescriptionLabel}" />
<Border Name="PlaceHolderBorder" Grid.Column="2" Margin="7"/>
<TextBox Grid.Row="1" Grid.Column="2" Text="{Binding CompanyName}" MaxLength="255"/>
<Border Name="DescriptionPlaceHolderBorder" Grid.Row="2" Margin="7"/>
<TextBox Grid.Row="2" Grid.Column="2" Text="{Binding Description}" VerticalScrollBarVisibility="Auto"
TextAlignment="Left" TextWrapping="Wrap" AcceptsReturn="True" MinHeight="60"
Width="{Binding ElementName=PlaceHolderBorder, Path=ActualWidth}"
Height="{Binding ElementName=DescriptionPlaceHolderBorder, Path=ActualHeight}"
/>
<StackPanel Orientation="Horizontal" Grid.Row="3" Grid.Column="2" Margin="5">
<Button Command="{Binding UpdateCommand}" Content="{Binding UpdateButtonLabel}"></Button>
<Button Command="{Binding ResetCommand}" Content="{Binding ResetButtonLabel}"></Button>
<Button Command="{Binding CloseConfirmCommand}" Content="{Binding CloseButtonLabel}"></Button>
</StackPanel>
</Grid>
</ScrollViewer>

Accessing TextBox in a DataTemplate

I have the XAML like this. (This code is just some part of my source code)
<UserControl x:Class="EmployeeClass"
...............>
.............
.............
<ListView x:Name="EmployeeList" Width="700" Height="500" Margin="10"
ItemsSource ="{Binding Source={x:Static local:Company.employeeList}}"
Background="Black"
ItemTemplateSelector="{DynamicResource myDataTemplateSelector}" Focusable="False"
IsSynchronizedWithCurrentItem="True">
</ListView>
</UserControl>
Here is one of my data template
<DataTemplate x:Key="SeniorEmployee" DataType="{x:Type local:ListEmployee}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Horizontal" VerticalAlignment="Top" Margin="10">
<Image x:Name="ProfilePicture" Source="{Binding Path=ProfilePict}" Stretch="Fill" Width="80" Height="80" VerticalAlignment="Top"></Image>
<StackPanel Orientation="Vertical" Margin="5">
<TextBlock Text="{Binding Path=Attribution}" Foreground="White" TextWrapping="Wrap" Width="400" VerticalAlignment="Top" HorizontalAlignment="Left"/>
<StackPanel Margin="7,5,0,7">
<UISkripsi3:CommandTextBox Name="AttributionTextBox" HorizontalAlignment="Left" Margin="10,5" Panel.ZIndex="1"
BannerText="Add to the attribution" FontSize="{DynamicResource LargeFontSize1}"
SpellCheck.IsEnabled="True" Style="{DynamicResource AttributionTextBoxStyle}"
TextWrapping="Wrap">
</UISkripsi3:CommandTextBox>
<Button Style="{DynamicResource StandardButtonStyle}" IsEnabled="{Binding ElementName=AttributionTextBox, Path=Text, Converter={StaticResource IsStringNullOrWhitespaceConverter}, ConverterParameter=Inverse}" Click="AttributionButtonClick" Height="22" HorizontalAlignment="Right" Margin="10,4,10,0" Panel.ZIndex="0" CommandTarget="{Binding ElementName=AttributionTextBox}" Content="Show" FontSize="{DynamicResource LargeFontSize1}">
</Button>
</StackPanel>
</Grid>
</DataTemplate>
If user type something in the AttributionTextBox and click the button, there will be a messagebox showing text typed by the user. I have tried
http://blogs.msdn.com/b/wpfsdk/archive/2007/04/16/how-do-i-programmatically-interact-with-template-generated-elements-part-ii.aspx
and visual tree helper at h*tp://msdn.microsoft.com/en-us/library/system.windows.media.visualtreehelper.aspx
My problem is, I can't find the AttributionTextBox in code behind. I also can't access the EmployeeList Listview because it wasn't generated in the code behind. Can anyone help me to solve the problem?
What about setting the Binding to TwoWay mode and accessing the Attribution property instead ? This seems much simpler than walking the visual tree.

Categories