我有DataGrid
我有几列。我在Button
内也有一个DataGrid
。现在当DataGrid
加载我想要更改按钮内容。我想检查“状态列”的状态。然后根据我要更改DataGrid
内的按钮内容。这就是我想要实现的目标
E.g
if(Status="Accepted"){
closeorderbtn.content="Close Order"
}
else{
closeorderbtn.content="Open Order"
}
Xaml文件
<DataGrid x:Name="dataGrid" FlowDirection="RightToLeft" SelectionMode="Single" MouseLeftButtonUp="dataGrid_MouseLeftButtonUp" MouseDoubleClick="dataGrid_MouseDoubleClick" Background="WhiteSmoke" RowBackground="White" HorizontalContentAlignment="Center" HorizontalAlignment="Left" ColumnWidth="*" Height="534" VerticalAlignment="Top" Width="1174" IsReadOnly="True" AutoGenerateColumns="False" BorderThickness="1" BorderBrush="LightGray" GridLinesVisibility="All" Margin="4,6,0,0">
<DataGrid.Columns>
<DataGridTextColumn Header="Total_Quantity" Binding="{Binding Total_Quantity}" FontFamily="B Nazanin" FontWeight="Bold"/>
<DataGridTextColumn Header="Rate" Binding="{Binding RatePerTon, StringFormat=\{0:n0\}}" FontFamily="B Nazanin" FontWeight="Bold"/>
<DataGridTextColumn Header="Discount" Binding="{Binding Discount}" FontFamily="B Nazanin" FontWeight="Bold"/>
<DataGridTextColumn Header="Final_" Binding="{Binding Final_Cost,StringFormat=\{0:n0\}}" FontFamily="B Nazanin" FontWeight="Bold"/>
<DataGridTextColumn Header="Payment_" Binding="{Binding Payment_Mode}" FontFamily="B Nazanin" FontWeight="Bold"/>
<DataGridTextColumn Header="status" Binding="{Binding Status}" FontFamily="B Nazanin" FontWeight="Bold"/>
<DataGridTemplateColumn Width="80" >
<DataGridTemplateColumn.CellTemplate >
<DataTemplate>
<Button x:Name="closeorderbtn" Content="" Click="CloseOrder" Background="#FF5890BF" Foreground="#FFBFBCBC" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
CS
IQueryable<Order> result;
result = (from s in ManagerClass.oSqlData.Orders select s);
dataGrid.ItemsSource = result;
答案 0 :(得分:1)
您可以将Style
与DataTrigger
:
<Button x:Name="closeorderbtn" Content="" Click="CloseOrder" Background="#FF5890BF" Foreground="#FFBFBCBC">
<Button.Style>
<Style TargetType="Button">
<Setter Property="Content" Value="Open Order" />
<Style.Triggers>
<DataTrigger Binding="{Binding Status}" Value="Accepted">
<Setter Property="Content" Value="Close Order" />
</DataTrigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>