在 RowStyle ->Template -> 内设置控件的属性控制模板->数据网格的边界

发布于 2024-12-03 21:36:30 字数 8858 浏览 0 评论 0原文

您好,如何设置放置在控件模板内的控件的属性。这是我的代码:

                    <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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

年少掌心 2024-12-10 21:36:30

您可以使用 BooleanToVisibilityConverter 绑定“btnSubmit”的可见性。

只需添加到 Resources:

<local:BooleanToVisibilityConverter x:Key="b2vconv" IsReversed="false"/>

然后使用:

 Visibility="{Binding Path=yourDataSourceColumnWithBoolValueForVisibility, 
                      Converter={StaticResource b2vconv} }"

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} }"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文