Hi,
I'm new to WPF and C#. In my XAML file, I have a simple Rectangle, where I am binding the width and the fill color:
<Rectangle HorizontalAlignment="Stretch" Height="20" Width="{Binding A.W1}" Fill="{Binding A.B1}"/>
When my program loads, I am reading the width and the color from a file using C# and dynamcially setting the A.W1 with an integer value and A.B1 with a SolidBrushColor value. I know my code is working, because, the width and the color are set correctly @ runtime.
However, the problem I am having is that I need to resize the width of the rectangle and the color during runtime, it does not show the changes in the window screen. How can one change the width/fill properties of a Rectangle during run-time. Note that there are no action events such as mouseover or clicking. I need to change the properties as and when I receive data in my program.
Are there any alternative options on how I can achieve this. Basically, I'm trying to create a bar chart that has a MIN, MAX and MEAN values where the MEAN value will be a red color rectangle that is always width=5. However, visually, the display should change as and when the MIN, MAX and MEAN values change in my code.
Would appreciate any help on this matter.
My XAML looks like the following....the Rectangles are in a DataTemplate and thus I can not get a handle on the Rectangles. I can update the NAME value during runtime and this reflects in the WPF.
The A class implements the INotifyPropertyChanged and has the the correct implementation for the get/set as the data list loaded when first loaded. Subsequent changes to the A.W1 and A.B1 values, reflect in the A OnPropertyChanged event manager, but does not reflect on the WPF screen.
<Window.Resources>
<ResourceDictionary>
<CollectionViewSource x:Key="TestDataSource"/>
</ResourceDictionary>
</Window.Resources>
<DockPanel Name="DP" LastChildFill="False">
<DataGrid x:Name="DG" ItemsSource="{Binding Source={StaticResource TestDataSource}}"
HeadersVisibility="Column"
HorizontalAlignment="Stretch"
CanUserAddRows="True"
AutoGenerateColumns="False"
Margin="0,0,0,0">
<DataGrid.Columns>
<DataGridTextColumn Header="Testing" Binding="{Binding NAME}" Width="130*"></DataGridTextColumn>
<DataGridTemplateColumn x:Name="ABC" Header="ABC Rectangle" Width="103">
<DataGridTemplateColumn.CellTemplate>
<!-- Cant get handle on DataTemplate or other child elements - WHY? -->
<DataTemplate x:Name="XYZ">
<Grid HorizontalAlignment="Left" VerticalAlignment="Stretch">
<StackPanel x:Name="STACK" Grid.Row="0" Orientation="Horizontal">
<Rectangle Name="R1" Height="18" Width="{Binding A.W1}" Fill="{Binding A.B1}"/>
<Rectangle Name="R2" Height="18" Width="{Binding A.W2}" Fill="{Binding A.B2}"/>
</StackPanel>
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</DockPanel>