WPF – MVVM and data binding using UniformGRID

I am trying to use some rectangles to design the back of the WPF chart. I am using MVVM, and I need to resize the rectangles uniformly. When defined by Xaml, this applies to the fixed “BucketCount” 4:










How to bind my ObservableCollection rectangle? There is no “ItemsSource” property on UniformGrid. Do I need to use ItemsControl? If so, what should I do?

Thanks in advance.

You can use the ItemsControl binding like this. ItemsSource Just a simple example of ObservableCollection






< br />









Update
It works for my usage scenario, but I might be missing something here. This is the complete code I tried. I got the same result from both

MainWindow.xaml< /p>
















< br />



< /pre>

MainWindow.xaml.cs

public partial class MainWindow: Window
{
public MainWindow()
{< br /> InitializeComponent();
BrushConverter brushConverter = new BrushConverter();
MyBrushes = new ObservableCollection();
MyBrushes.Add(brushConverter.ConvertFrom("#22ADD8E6") as Brush);
MyBrushes.Add(brushConverter.ConvertFrom("#22D3D3D3") as Brush);
MyBrushes.Add(brushConverter.ConvertFrom("#22ADD8E6") as Brush);
MyBrushes.Add(brushConverter.ConvertFrom("#22D3D3D3") as Brush);
this.DataContext = this;
}

public ObservableColl ection MyBrushes
{
get;
set;
}
}

I tried to use Some rectangles are used to design the back of the WPF chart. I am using MVVM and I need to resize the rectangles uniformly. When defined by Xaml, this applies to the fixed "BucketCount" 4:




< Rectangle Grid.Row="0" Grid.Column="0" Fill="#22ADD8E6" />





How to bind my ObservableCollection rectangle? There is no "ItemsSource" property on UniformGrid. Do I need to use ItemsControl? If so, what should I do?

Thanks in advance.

You can use the ItemsControl binding like this. ItemsSource is just a simple example of ObservableCollection








< /ItemsControl.ItemsPanel>







Update
It works for my usage scenario, but I might be missing something here. This is the complete code I tried. I got the same result from both

MainWindow.xaml





















MainWindow.xaml.cs

public partial class MainWindow: Window
{
public MainWindow()
{
InitializeComponent();
BrushConverter brushConverter = new BrushConverter( );
MyBrushes = new ObservableCollection();
MyBrushes.Add(brushConverter.ConvertFrom("#22ADD8E6") as Brush);
MyBrushes.Add(brushConverter.ConvertFrom(" #22D3D3D3") as Brush);
MyBrushes.Add(brushConverter.ConvertFrom("#22ADD8E6") as Brush);
MyBrushes.Add(brushConverter.ConvertFrom("#22D3D3D3") as Brush);
this.DataContext = this;
}

public ObservableCollection MyBrushes
{
get;
set;
}
}

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 4066 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.