Set the property of a control inside the RowStyle ->Template -> ControlTemplate -> Border of the DataGrid
Hi how can I set the property of a control placed inside a controltemplate. Here is my code:
<dg:DataGrid Name="questionList"
HeadersVisibility="None"
AutoGenerateColumns="False"
Background="White"
Margin="42,32,43,0"
BorderThickness="0"
GridLinesVisibility="None"
CanUserAddRows="False"
HorizontalGridLinesBrush="#FFCCCCCC"
Cursor="Hand"
MaxHeight="483"
FocusVisualStyle="{x:Null}"
PreviewMouseLeftButtonUp="questionnaireList_PreviewMouseLeftButtonUp"
CanUserReorderColumns="False"
CanUserResizeColumns="False"
CanUserSortColumns="False"
HorizontalScrollBarVisibility="Hidden"
SelectionMode="Single">
<dg:DataGrid.CellStyle>
<Style TargetType="{x:Type dg:DataGridCell}">
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
</Style>
</dg:DataGrid.CellStyle>
<dg:DataGrid.RowStyle>
<Style TargetType="{x:Type dg:DataGridRow}">
<Setter Property="Background" Value="{Binding QuestionImage, Converter={x:Static my:StatusColorConverter.instance}}" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type dg:DataGridRow}">
<Border BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
开发者_JAVA技巧 SnapsToDevicePixels="True">
<dg:SelectiveScrollingGrid>
<dg:SelectiveScrollingGrid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</dg:SelectiveScrollingGrid.ColumnDefinitions>
<dg:SelectiveScrollingGrid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</dg:SelectiveScrollingGrid.RowDefinitions>
<dg:DataGridCellsPresenter Grid.Column="1"
ItemsPanel="{TemplateBinding ItemsPanel}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
<Path Grid.Row="2" Grid.ColumnSpan="2"
Data="M0,0.5 L1,0.5"
Stretch="Fill"
Stroke="#FFCCCCCC"
StrokeThickness="1"
StrokeDashArray="1.0 2.0"/>
<Button Style="{DynamicResource btnSubmitStyle}"
Width="106"
Height="47"
Name="btnSubmit"
Margin="0,13,0,13"
Click="btnSubmit_Click"
Visibility="Hidden"
Grid.Column="3"
Cursor="Hand">
<StackPanel Orientation="Horizontal"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Image Source="/iQuestionnaire;component/Images/arrow.png" Width="17" Height="16" />
<TextBlock Margin="5,0,0,0"
FontSize="16"
Width="Auto"
Text="Submit"/>
</StackPanel>
</Button>
</dg:SelectiveScrollingGrid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
</Style>
</dg:DataGrid.RowStyle>
<dg:DataGrid.Columns>
<dg:DataGridTemplateColumn Width="69*">
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Margin="12,16,0,17"
FontSize="20"
Foreground="#0891F1"
Text="{Binding Path=QuestionNum}"
TextWrapping="Wrap"/>
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>
<dg:DataGridTemplateColumn Width="601*">
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<TextBlock FontSize="14"
Foreground="#666666"
Text="{Binding Path=QuestionDesc}"
TextWrapping="Wrap"
TextAlignment="Justify"
Margin="0,16,0,17" />
</Grid>
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>
<dg:DataGridTemplateColumn Width="117*">
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Image Source="{Binding Path=QuestionImage}"
Stretch="None"
VerticalAlignment="Top"
HorizontalAlignment="Right"
Margin="0,16,18,17" />
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>
</dg:DataGrid.Columns>
</dg:DataGrid>
I want to set the Visibility property of the "btnSubmit" button at run time. Is this possible?
You can bind the Visibility of the 'btnSubmit' using BooleanToVisibilityConverter.
Just add to Resources:
<local:BooleanToVisibilityConverter x:Key="b2vconv" IsReversed="false"/>
then use:
Visibility="{Binding Path=yourDataSourceColumnWithBoolValueForVisibility,
Converter={StaticResource b2vconv} }"
精彩评论