There is another headache with the DataTemplate.
Description: Using Silverlight 4, Mvvm, etc. (Standard toolkit for Silverlight LOB application developers).
The list of objects was successfully bound to the DataGrid . One property (nullable bool BoolValue) is responsible for the behavior of the object and is presented in a datagrid with an image, clicking on which changes the visibility of some controls in the LayoutRoot element.
Problem: The problem is that, unfortunately or fortunately, the ElementName binding in the DataTemplate does not see other elements than those that are placed in this template.
Code example:
<navigation:DataGridTemplateColumn Width="40" CanUserReorder="True" CanUserSort="False"> <navigation:DataGridTemplateColumn.CellTemplate> <DataTemplate> <Border Background="GhostWhite"> <Grid> <Image x:Name="ImageWithTrigger" Grid.Column="1" Margin="10,4,0,0" HorizontalAlignment="Left" VerticalAlignment="Center" Cursor="Hand" Source="images/someImage.png" Stretch="None" Visibility={Binding BoolValue, Converter={StaticResource boolToVisibilityConverter} }> <i.Interaction.Triggers> <i:EventTrigger EventName="MouseLeftButtonDown"> <AttachedBehaviors:TrickyBehavior FrameworkElementToHide="{Binding ElementName=FirstControlOutside}" FrameworkElementToShow="{Binding ElementName=SecoundControlOutside}"/> </i:EventTrigger> </i:Interaction.Triggers> </Grid> </Border> </DataTemplate> </navigation:DataGridTemplateColumn.CellTemplate> </navigation:DataGridTemplateColumn>
In the above example, FrameworkElementToHide and FrameworkElementToShow are always zero.
There are many similar problems and solutions on the Internet, but I have not found a simple and elegant way to solve this problem.
source share