Hey guys i m very new here so sorry if this is not the right place to post it but i really dont know where else i'd post it.
I'm new at WPF and i don't know that much yet but i'm still learning.
so here is my issue
I want to make a simple financial manager witch takes the the content of the texboxes into my datagrid and this all works but now i wanna change the background of CellRows into red.
I have a few Textboxes and one of them is for numbers (txt_amountID) like 42$ and when i type -42$ it should change the background of the CellRow into red
Here is my XAML Code:
And here is my Code behinde but i just want to make it with XMAL if its possible, if not then please help me to make a if-else solution
I'm new at WPF and i don't know that much yet but i'm still learning.
so here is my issue
I want to make a simple financial manager witch takes the the content of the texboxes into my datagrid and this all works but now i wanna change the background of CellRows into red.
I have a few Textboxes and one of them is for numbers (txt_amountID) like 42$ and when i type -42$ it should change the background of the CellRow into red
Here is my XAML Code:
XAML COde:
<DataGrid x:Name="dtg_aus" Grid.ColumnSpan="2" AutoGenerateColumns="True" HorizontalScrollBarVisibility="Disabled" VerticalScrollBarVisibility="Auto" >
<DataGrid.Columns>
<DataGridTextColumn Header="Name" Width="*" Binding="{Binding nameID}" />
<DataGridTextColumn Header="Runtime" Width="*" Binding="{Binding runtimeID}"/>
<DataGridTextColumn x:Name="dataGridTextColumn" Header="amount" Width="*" Binding="{Binding amountID}" />
<DataGridTemplateColumn>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button x:Name="btn_del" Click="btn_del_click">
<Button.Background>
<ImageBrush ImageSource="/icon_trash.png"/>
</Button.Background>
</Button>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
/// Here i tryed it with binding but it doesnt worked that well, actually doesnt worked at all
<DataGrid.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="Background" Value="LightGreen" />
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=txt_amountID, Path=IsNegative}" Value="True">
<Setter Property="Background" Value="LightPink" />
</DataTrigger>
</Style.Triggers>
</Style>
</DataGrid.CellStyle>
<Button x:Name="btn_take" Content="Take" Click="btn_take_Click"/>
<TextBox x:Name="txt_nameID"/>
<TextBox x:Name="txt_runtimeID"/>
<TextBox x:Name="txt_amountID"/>
</DataGrid>
And here is my Code behinde but i just want to make it with XMAL if its possible, if not then please help me to make a if-else solution
C# Code:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
public class Booking
{
public string nameID {get; set;}
public string runtimeID {get; set;}
public string amountID {get; set;}
}
private void btn_take_Click(object sender, RoutedEventArgs e)
{
Booking var = new Booking();
var.nameID = txt_nameID.Text;
var.runtimeID = txt_runtimeID.Text;
var.amoutID = txt_aboutID.Text;
dtg_aus.Items.Add(var);
}