Hi guys,
I have an ItemsControl with the ItemsPanel set to Canvas. I am setting the Canvas.Left, Canvas.Top properties for the container however doesn't seem to work. Same approach works fine in WPF. Here is the mainpage.xaml.h
[Windows::UI::Xaml::Data::BindableAttribute]
public ref class Item sealed
{
public:
property double X;
property double Y;
property double W;
property double H;
};
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
[Windows::UI::Xaml::Data::BindableAttribute]
public ref class MainPage sealed
{
public:
MainPage();
property Windows::Foundation::Collections::IVector<Item^>^ Items
{
Windows::Foundation::Collections::IVector<Item^>^ get()
{
return _items;
}
}
protected:
virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs^ e) override;
private:
Windows::Foundation::Collections::IVector<Item^>^ _items;
};
here is the ctor for the MainPage.xaml.cpp
MainPage::MainPage()
{
_items = ref new Vector<Item^>();
auto item = ref new Item();
item->X = 100;
item->Y = 20;
item->W = 40;
item->H = 40;
_items->Append(item);
item = ref new Item();
item->X = 200;
item->Y = 120;
item->W = 40;
item->H = 40;
_items->Append(item);
item = ref new Item();
item->X = 100;
item->Y = 320;
item->W = 70;
item->H = 340;
_items->Append(item);
DataContext = this;
InitializeComponent();
}
and the MainPage.xaml
<Page
x:Class="App1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<ItemsControl ItemsSource="{Binding Items}" Background="LightCoral" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<Canvas Background="Black"/>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Rectangle Fill="White" Stroke="Green" StrokeThickness="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
<ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter">
<Setter Property="Canvas.Left" Value="{Binding X}"/>
<Setter Property="Canvas.Top" Value="{Binding Y}"/>
<Setter Property="Width" Value="{Binding W}"/>
<Setter Property="Height" Value="{Binding H}"/>
</Style>
</ItemsControl.ItemContainerStyle>
</ItemsControl>
</Grid>
</Page>
Any idea how to get this working?
Regards,
Stefan