在 RowStyle ->Template -> 内设置控件的属性控制模板->数据网格的边界
您好,如何设置放置在控件模板内的控件的属性。这是我的代码:
<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}"
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>
我想在运行时设置“btnSubmit”按钮的可见性属性。这可能吗?
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}"
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 BooleanToVisibilityConverter 绑定“btnSubmit”的可见性。
只需添加到 Resources:
然后使用:
You can bind the Visibility of the 'btnSubmit' using BooleanToVisibilityConverter.
Just add to Resources:
then use: