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.
< 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>
< /pre>
< br />
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 ectionMyBrushes
{
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>
ItemsControl.ItemTemplate>
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 ObservableCollectionMyBrushes
{
get;
set;
}
}