简体   繁体   English

更改数据网格中的按钮文本和颜色。 WPF c#

[英]Change button text and color in a datagrid. WPF c#

I have a datagrid table in WPF which is bound to a model.我在 WPF 中有一个数据网格表,它绑定到 model。 How do I change the button text, and color based on a bool property from the model.如何根据 model 的布尔属性更改按钮文本和颜色。

<DataGrid x:Name="FileReviewGrid" ItemsSource="{Binding}" CanUserSortColumns="True" CanUserAddRows="False" AutoGenerateColumns="False" IsReadOnly="True"
                      ColumnHeaderStyle="{StaticResource HeaderStyle}"
                  materialDesign:DataGridAssist.CellPadding="13 8 8 8" materialDesign:DataGridAssist.ColumnHeaderPadding="8" HorizontalContentAlignment="Stretch" Background="{x:Null}">
                    <DataGrid.Columns>
                        <DataGridTemplateColumn>
                            <DataGridTemplateColumn.CellTemplate>
                                <DataTemplate>
                                    <Button Click="Decrypt_Click" Height="25" Margin="0,-10" >
                                        <StackPanel Orientation="Horizontal">
                                            <materialDesign:PackIcon Kind="FileExport" />
                                            <TextBlock>Decrypt</TextBlock>
                                        </StackPanel>

                                    </Button>
                                </DataTemplate>
                            </DataGridTemplateColumn.CellTemplate>
                        </DataGridTemplateColumn>

you should create tow datatemplates one for the first style wich will selected by default and the second for the true value and you can hide it or show it depending on the bool value you can also create a style and bind it to the model您应该为默认选择的第一个样式创建两个数据模板,为真实值选择第二个,您可以根据布尔值隐藏或显示它您还可以创建一个样式并将其绑定到 model

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM