简体   繁体   中英

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

I have a datagrid table in WPF which is bound to a model. How do I change the button text, and color based on a bool property from the 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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