Declarative GridView in XAML in WinRT - xaml

Is there a way to define a GridView purely declaratively in XAML? Every example I see defines the Category/Group Name value in code behind, then each item has a Title / Subtitle. I would really like to figure out a way to do something like the following:
<GridView
x:Name="itemGridView"
AutomationProperties.AutomationId="ItemGridView"
AutomationProperties.Name="Grouped Items"
Grid.Row="1"
Margin="0,-3,0,0"
Padding="116,0,40,46"
ItemTemplate="{StaticResource Standard250x250ItemTemplate}">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<GridView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<Grid Margin="1,0,0,6">
<Button
AutomationProperties.Name="Group Title"
Content="{Binding Tag}"
Style="{StaticResource TextButtonStyle}"/>
</Grid>
</DataTemplate>
</GroupStyle.HeaderTemplate>
<GroupStyle.Panel>
<ItemsPanelTemplate>
<VariableSizedWrapGrid Orientation="Vertical" Margin="0,0,80,0"/>
</ItemsPanelTemplate>
</GroupStyle.Panel>
</GroupStyle>
</GridView.GroupStyle>
<GridView.Items>
<Grid x:Name="tab1" Tag="Tab 1" AutomationProperties.Name="Group Title" HorizontalAlignment="Left" Width="250" Height="250">
<!-- Tab COntent -->
</Grid>
<Grid x:Name="tab2" Tag="Tab 2" AutomationProperties.Name="Tab 2" HorizontalAlignment="Left" Width="250" Height="250">
<!-- Tab Content -->
</Grid>
</GridView.Items>
</GridView>
Unfortunately this example doesn't work. I can't seem to figure out how to set a Group name declaratively. Thank you for any insights.

I think the following method is great way to customize any Gridview.
*If you like to implement multiple group style in your Grid, pls do this work:
Step 1. Create a GroupSelector class and override SelectStyleCore function:
public class GroupStyleSelector : StyleSelector
{
public Style GroupStyle1 { get; set; }
public Style GroupStyle2 { get; set; }
protected override Windows.UI.Xaml.Style SelectStyleCore(object item, Windows.UI.Xaml.DependencyObject container)
{
var viewGroup = item as ICollectionViewGroup;
if (viewGroup != null)
{
//var groupModel = viewGroup.Group as YourGroupModel;
if (condition1)
{
return GroupStyle1;
}
else if (condition2)
{
return GroupStyle2;
}
}
}
}
Step 2. in XAML resource, add these code:
<Style x:Key="YourGroupStyle1" TargetType="GroupItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="GroupItem">
<!-- Add your custom layout here for Group style 1 -->
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="YourGroupStyle2" TargetType="GroupItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="GroupItem">
<!-- Add your custom layout here for Group style 1 -->
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<customstyle:GroupStyleSelector x:Key="GroupStyleSelector"
GroupStyle1="{StaticResource GroupStyle1}"
GroupStyle2="{StaticResource GroupStyle2}"/>
customstyle is link to your namespace that store GroupStyleSelector class.
Step 3. Apply style selector for GridView control
If you you want to customize HeaderTemplate pls let me know, if not user current as GridApp sample from Microsoft.
If you like to customize each item layout on a group, you also do simiar to GroupStyleSelector:
Create DataTemplateSeletor (inherit from TemplateSelector) then assign it on the GridView control
<GridView ItemTemplateSelector="{StaticResource ItemTemplateSelector}">
<GridView.GroupStyle>
<GroupStyle ContainerStyleSelector="{StaticResource GroupStyleSelector}">
<GroupStyle.HeaderTemplate .../>
</GridView.GroupStyle>
Hope that my guide is clear for you.
If any quesion, pls discuss.

Related

How do I tell when a ListViewItem gets focus?

I have a UWP XAML ListView, and I would like to handle focus events when I switch between items within with arrow keys. However, I cannot figure out how to handle focus events for my items:
<ListView ItemsSource="{x:Bind Items}"
CanDragItems="True" CanReorderItems="True" AllowDrop="True"
SelectionMode="None" IsItemClickEnabled="True" ItemClick="ListView_ItemClick">
<ListView.ItemTemplate>
<DataTemplate x:DataType="x:String">
<!-- Never fires, even with Control.IsTemplateFocusTarget="True" : -->
<StackPanel GotFocus="StackPanel_GotFocus">
<!-- Never fires: -->
<TextBlock Text="{x:Bind}" GotFocus="TextBlock_GotFocus" />
<Button Content="Foo" IsTabStop="False" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<!-- Never fires: -->
<ListViewItemPresenter [...]
GotFocus="Root_GotFocus" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ListView.ItemContainerStyle>
</ListView>
Where else could I listen to get these focus events?
Thanks!
Disclaimer: I work for Microsoft.
When using <ListView> or <ListBox> you don't need to use GotFocus events.
Instead you use SelectionChanged event in the main <listView> control, and in code get the index of the <ListViewItem> that got selected.
SelectionChanged event is triggered every time the user change his selection in the <ListView>.
ListView.SelectedIndex returns the index number of the selected <ListViewItem> First item is 0.
Here is an example:
XAML:
<Image x:Name="img"/>
<ListView x:Name="listView" SelectionChanged="ListView_SelectionChanged">
<ListViewItem>Image 1</ListViewItem>
<ListViewItem>Image 2</ListViewItem>
<ListViewItem>Image 3</ListViewItem>
</ListView>
C#:
private void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
int num = listView.SelectedIndex + 1;
img.Source = new BitmapImage(new Uri($"ms-appx:///Assets/Pictures/image{num}.jpg"));
}

Close UWP flyout with listview item click

I'm trying to close a flyout on a listview item click. The problem is that during runtime, the CallMethodAction can't find the hide method of the flyout menu. How can I fix this?
<Flyout x:Name="UnitFlyout">
<ListView x:Name="ArmyUnitListView" ItemsSource="{Binding Source={StaticResource ArmyUnitCollection}}" SelectionMode="Single" >
<ListView.GroupStyle>
<GroupStyle HidesIfEmpty="True" HeaderTemplate="{StaticResource ArmyListDataGroupTemplate}" />
</ListView.GroupStyle>
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="SelectionChanged">
<core:InvokeCommandAction Command="{Binding AddUnitCommand}" CommandParameter="{Binding SelectedItem, ElementName=ArmyUnitListView}" />
<core:CallMethodAction TargetObject="UnitFlyout" MethodName="Hide"/>
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</ListView>
</Flyout>
I made a demo and reproduced the problem.The reason lies on the ElementName binding to popups.
ElementName bindings do not work within Flyout’s and other popups
Please see this Case.
I found this blog, which offers a workaround to fix this problem. And I've tried it with a demo,which works fine.
In your case, you can copy the FlyoutHelpers (in blog) class to your project; And add IsFlyoutOpen and SendCommand to your ViewModel like below:
public class MainPageViewModel : ViewModelBase
{
public RelayCommand SendCommand { get; set; }// bind this to your xaml
public List<String> MyData { get; set; }
private bool isFlyoutOpen;
public bool IsFlyoutOpen// bind this to your xaml
{
get { return isFlyoutOpen; }
set { this.Set(() => IsFlyoutOpen, ref isFlyoutOpen, value); }
}
public MainPageViewModel()
{
SendCommand = new RelayCommand(() =>
{
// Doing processing...
IsFlyoutOpen = false;
});
MyData = new List<string> { "winffee", "123", "this Data" };//this is sample data
}
}
And Bind the commands and properties to your xaml:
<Flyout x:Name="UnitFlyout"
local:FlyoutHelpers.Parent="{Binding ElementName=myBtn}"
local:FlyoutHelpers.IsOpen="{Binding IsFlyoutOpen,Mode=TwoWay}">
<ListView x:Name="ArmyUnitListView" SelectionMode="Single" ItemsSource="{Binding MyData}">
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="SelectionChanged" SourceObject="{Binding ElementName=ArmyUnitListView}">
<!--<core:InvokeCommandAction Command="{Binding AddUnitCommand}" CommandParameter="{Binding SelectedItem, ElementName=ArmyUnitListView}" />-->
<core:InvokeCommandAction Command="{Binding SendCommand}" />
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</ListView>
</Flyout>
Here is my entire Demo: FlyoutSample

Windows 8 XAML RT toolkit Color palette - Column Charts

I'm building a windows store application and trying to use the chart component in XAML RT Toolkit. Now the problem is I want to represent each column bar with a specific colou. But then I'm not finding a way to do it. There's a similar question which is addressed for the pie chart color palette. But this doesn't seem to work in Column charts. Can somebody help ?
Hi Rajkumar,
We too have a similar problem. Finally succeeded. Please check the following link.
http://blogs.msdn.com/b/delay/archive/2009/02/04/columns-of-a-different-color-customizing-the-appearance-of-silverlight-charts-with-re-templating-and-mvvm.aspx
To give different color, the essence is following.
Step 1.
Create a style under Page.Resource as follows.
<Page.Resources>
<Style
x:Key="**ColorByPreferenceColumn**"
TargetType="charting:ColumnDataPoint">
<Setter Property="Background" Value="DarkGray"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate
TargetType="charting:ColumnDataPoint">
<Border
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}">
<Grid Background="{Binding **ColorBackGround**}">
<Rectangle>
<Rectangle.Fill>
<LinearGradientBrush>
<GradientStop Color="#77ffffff" Offset="0"/>
<GradientStop Color="#00ffffff" Offset="1"/>
</LinearGradientBrush>
</Rectangle.Fill>
</Rectangle>
<Border BorderBrush="#ccffffff" BorderThickness="1">
<Border BorderBrush="#77ffffff" BorderThickness="1"/>
</Border>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Step 2.
Apply the style to the chart control.
<charting:Chart x:Name="BuildStatusChart" Title="Build Status" Foreground="Black" Margin="20,20,20,20">
<charting:Chart.Series>
<Series:ColumnSeries Title="Build Status" ItemsSource="{Binding Items}"
IndependentValueBinding="{Binding Index}" HorizontalContentAlignment="Center"
DependentValueBinding="{Binding BuildTime}"
IsSelectionEnabled="False" SelectionChanged="OnSelectionChanged" DataPointStyle="{StaticResource ColorByPreferenceColumn}" >
</Series:ColumnSeries>
</charting:Chart.Series>
</charting:Chart>
Step 3:
Note : the style name is "ColorByPreferenceColumn" and color for each bar will be represented by "ColorBackGround". Search the above code segment , to know how it is applied. FInal thing is on code side have class with "ColorBackGround" peoperty.
public class Build : BindableBase
{
//Build Class
public Build() {}
private SolidColorBrush _colorBackGround;
public SolidColorBrush ColorBackGround
{
get { return _colorBackGround; }
set { _colorBackGround = value; }
}
// And your properties......
}
Step 5:
Ofcpourse as you know,
Set the the binding collection. In our case it was
((ColumnSeries)this.BuildStatusChart.Series[0]).ItemsSource = items; // items collection of individual objects.
Best Regards,
Anish.A.R

How to implement SemanticZoom?

I have an application that it's main page is organized like this:
Grid (LayoutRoot)
VisualStateManager (FullLandscape, FullPortrait, Filled, Snap)
Grid (Back button and page title)
ScrollViewer (FullLandscape View )
StackPanel (Horizontal)
GridView (non grouped GridView)
GridView (grouped GridView)
GridView (non grouped GridView)
GridView (grouped GridView)
GridView (grouped GridView)
ScrollViewer (Snap View)
Grid
ListView (Vertical)
My questions are:
Do I have to provide a SemanticZoom for each page in my application in order for the application to pass certification?
If I want to provide a SemanticZoom for this main page, how do I do it? i.e. where do I insert the SemanticZoom control?
( I read the article: Quickstart: Adding SemanticZoom controls:)
<SemanticZoom.ZoomedOutView>
<!-- Put the GridView for the zoomed out view here. -->
</SemanticZoom.ZoomedOutView>
<SemanticZoom.ZoomedInView>
<!-- Put the GridView for the zoomed in view here. -->
</SemanticZoom.ZoomedInView>
Thanks,
EitanB
It's a bit hard from to understand what you are trying to achieve from what you have written above, but I'll do my best to answer you questions.
1) SemanticZoom usage is not mandatory to pass certification. It's a nice feature that helps you present data in a neat way to the user and when used appropriately is pretty darn cool.
But, it's just a control. Give us some more information about your project and maybe we can help you decide if it will add something extra or not to the application.
Start easy and work into the details later.
2) Download the SemanticZoom example from MSDN and have a look at the code. BAsically it looks like this:
<Page.Resources>
<CollectionViewSource x:Name="cvs2" IsSourceGrouped="true" />
</Page.Resources>
<Grid x:Name="ContentPanel" VerticalAlignment="Top" HorizontalAlignment="Left">
<SemanticZoom x:Name="semanticZoom" VerticalAlignment="Bottom">
<SemanticZoom.ZoomedOutView>
<GridView ScrollViewer.IsHorizontalScrollChainingEnabled="False">
<GridView.ItemTemplate>
<DataTemplate>
<TextBlock
Text="{Binding Group.Key}"
FontFamily="Segoe UI Light"
FontSize="24"/>
</DataTemplate>
</GridView.ItemTemplate>
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<WrapGrid ItemWidth="75" ItemHeight="75" MaximumRowsOrColumns="1" VerticalChildrenAlignment="Center" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<GridView.ItemContainerStyle>
<Style TargetType="GridViewItem">
<Setter Property="Margin" Value="4" />
<Setter Property="Padding" Value="10" />
<Setter Property="BorderBrush" Value="Gray" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
</Style>
</GridView.ItemContainerStyle>
</GridView>
</SemanticZoom.ZoomedOutView>
<SemanticZoom.ZoomedInView>
<GridView ItemsSource="{Binding Source={StaticResource cvs2}}" IsSwipeEnabled="True" ScrollViewer.IsHorizontalScrollChainingEnabled="False">
<GridView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="10,10,0,0" HorizontalAlignment="Left" Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Image Source="{Binding Image}" Height="60" Width="60" VerticalAlignment="Center" Margin="0,0,10,0"/>
<TextBlock TextWrapping="Wrap" Foreground="{StaticResource ApplicationForegroundThemeBrush}" Width="200" VerticalAlignment="Center" Text="{Binding Title}" HorizontalAlignment="Left" FontFamily="Segoe UI" />
</StackPanel>
</DataTemplate>
</GridView.ItemTemplate>
<GridView.GroupStyle>
<GroupStyle>
<GroupStyle.HeaderTemplate>
<DataTemplate>
<TextBlock Text='{Binding Key}' Foreground="{StaticResource ApplicationForegroundThemeBrush}" Margin="5" FontSize="18" FontFamily="Segoe UI Light" />
</DataTemplate>
</GroupStyle.HeaderTemplate>
<GroupStyle.ContainerStyle>
<Style TargetType="GroupItem">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="GroupItem">
<StackPanel Orientation="Vertical">
<ContentPresenter Content="{TemplateBinding Content}" />
<ItemsControl x:Name="ItemsControl" ItemsSource="{Binding GroupItems}" />
</StackPanel>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</GroupStyle.ContainerStyle>
<GroupStyle.Panel>
<ItemsPanelTemplate>
<VariableSizedWrapGrid Orientation="Vertical" MaximumRowsOrColumns="3" />
</ItemsPanelTemplate>
</GroupStyle.Panel>
</GroupStyle>
</GridView.GroupStyle>
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<WrapGrid Orientation="Vertical" MaximumRowsOrColumns="1" />
</ItemsPanelTemplate>
</GridView.ItemsPanel>
<Button Visibility="Collapsed"/>
</GridView>
</SemanticZoom.ZoomedInView>
</SemanticZoom>
</Grid>
and codebehind:
StoreData _storeData = null;
public ScenarioOutput1()
{
InitializeComponent();
_storeData = new StoreData();
List<GroupInfoList<object>> dataCategory = _storeData.GetGroupsByCategory();
cvs1.Source = dataCategory;
}
Thanks for your answer.
I did see the example and it is clear to me. What is not clear to me is: I have on this one page multiple GridViews not just one like in the example. The question that is open in my mind is: Should I follow the example code for each of the GridViews on the page, or is there a way to do it once for the page that will cover all GridViews? Please see the pseudo code below.
Thanks,
EitanB
VisualStateManager (FullLandscape, FullPortrait, Filled, Snap)
Grid (Back button and page title)
ScrollViewer (FullLandscape View )
StackPanel (Horizontal)
<SemanticZoom x:Name="semanticZoom1" VerticalAlignment="Bottom">
<SemanticZoom.ZoomedOutView>
GridView (non grouped GridView)
</SemanticZoom.ZoomedOutView>
<SemanticZoom.ZoomedInView>
GridView (non grouped GridView - Semantic Version)
</SemanticZoom.ZoomedInView>
</SemanticZoom>
<SemanticZoom x:Name="semanticZoom2" VerticalAlignment="Bottom">
<SemanticZoom.ZoomedOutView>
GridView (grouped GridView)
</SemanticZoom.ZoomedOutView>
<SemanticZoom.ZoomedInView>
GridView (grouped GridView - Semantic Version)
</SemanticZoom.ZoomedInView>
</SemanticZoom>
<SemanticZoom x:Name="semanticZoom3" VerticalAlignment="Bottom">
<SemanticZoom.ZoomedOutView>
GridView (non grouped GridView)
</SemanticZoom.ZoomedOutView>
<SemanticZoom.ZoomedInView>
GridView (non grouped GridView - Semantic Version)
</SemanticZoom.ZoomedInView>
</SemanticZoom>
<SemanticZoom x:Name="semanticZoom4" VerticalAlignment="Bottom">
<SemanticZoom.ZoomedOutView>
GridView (grouped GridView)
</SemanticZoom.ZoomedOutView>
<SemanticZoom.ZoomedInView>
GridView (grouped GridView - Semantic Version)
</SemanticZoom.ZoomedInView>
</SemanticZoom>
<SemanticZoom x:Name="semanticZoom5" VerticalAlignment="Bottom">
<SemanticZoom.ZoomedOutView>
GridView (grouped GridView)
</SemanticZoom.ZoomedOutView>
<SemanticZoom.ZoomedInView>
GridView (grouped GridView - Semantic Version)
</SemanticZoom.ZoomedInView>
</SemanticZoom>
ScrollViewer (Snap View)
Grid
ListView (Vertical)
The way to do it is like I posted in my question, i.e. the question was asking if it is the right way and the answer is yes.
EitanB

Gridview items as squares in WinRT (metro)

I've been struggeling with this a few days now and can't get it to work.
Maybe I'm not as good XAML programmer that I hoped I would be :)
Anyhow, my problem is that i want to bind a number of elements to a GridView and make them appear as squares without setting any width and height. The reason for this is that I want my GridView items to grow/shrink and expand to maximum size as the resolution or screen size vary.
Here is my XAML:
<UserControl.Resources>
<Style x:Key="MyItemContainerStyle" TargetType="ListViewItem">
<Setter Property="FontFamily" Value="Segoe UI" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
<!--<Setter Property="Height" Value="{Binding RelativeSource={RelativeSource Self}, Path=Width}" />-->
</Style>
<DataTemplate x:Key="MyItemTemplate">
<Border CornerRadius="4"
BorderBrush="Black"
BorderThickness="1"
Background="Blue">
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center">X</TextBlock>
</Border>
</DataTemplate>
<ItemsPanelTemplate x:Key="MyItemsPanelTemplate">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center" />
</ItemsPanelTemplate>
</UserControl.Resources>
<Grid Background="White">
<GridView x:Name="MyGrid"
UseLayoutRounding="True"
ItemTemplate="{StaticResource MyItemTemplate}"
ItemsPanel="{StaticResource MyItemsPanelTemplate}"
ItemContainerStyle="{StaticResource MyItemContainerStyle}"
ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto">
</GridView>
</Grid>
And this is my code-behind:
public sealed partial class BlankPage : Page
{
public BlankPage()
{
this.InitializeComponent();
MyGrid.Items.Add(new ListViewItem { Content = 1 });
MyGrid.Items.Add(new ListViewItem { Content = 2 });
MyGrid.Items.Add(new ListViewItem { Content = 3 });
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached. The Parameter
/// property is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
}
This however produces an output like this (rectangular items, not squares):
I would appreciate if someone who knows a bit more about XAML and WinRT (metro) development than I do, could explain this for me and maybe give me a working example.
Thanx!
EDIT
I got a tip to wrap my Border in a Viewbox as it seems to have some scaling/stretching abilities.
I played around a couple of hours but I can't really get it to work 100%.
This is my XAML now:
<UserControl.Resources>
<Style x:Key="MyItemContainerStyle" TargetType="ListViewItem">
<Setter Property="FontFamily" Value="Segoe UI" />
<Setter Property="FontWeight" Value="Bold" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
</Style>
<DataTemplate x:Key="MyItemTemplate">
<Viewbox>
<Border CornerRadius="3"
BorderBrush="Black"
BorderThickness="1">
<Grid Background="Blue" MinHeight="50" MinWidth="50">
<TextBlock VerticalAlignment="Center" HorizontalAlignment="Center">X</TextBlock>
</Grid>
</Border>
</Viewbox>
</DataTemplate>
<ItemsPanelTemplate x:Key="MyItemsPanelTemplate">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center">
</StackPanel>
</ItemsPanelTemplate>
</UserControl.Resources>
<Grid Background="White">
<GridView x:Name="MyGrid"
UseLayoutRounding="True"
ItemTemplate="{StaticResource MyItemTemplate}"
ItemsPanel="{StaticResource MyItemsPanelTemplate}"
ItemContainerStyle="{StaticResource MyItemContainerStyle}"
ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled">
</GridView>
</Grid>
This produces this output:
Now it seems to stretch itself to a sqaure, but it sretches itself outside the screen. I also ran this example in several resoultions and screen sizes and it shows the same output, which means it scales correctly.
Help would be appreciated.
Thanx!
Your commented out binding is close to something that could sort of work - only you would need to bind to ActualWidth:
<Setter Property="Height" Value="{Binding ActualWidth, RelativeSource={RelativeSource Self}}" />
Overall I would suggest using hardcoded values - they make things easier on the CPU to layout, easier to deterministically design and will get scaled by Windows when screen size and resolution will require that. If you want more control over that - you can bind both Width and Height to the same value from a view model that you change depending on the need or write a converter that will convert a hardcoded Width/Height value to actual value depending on detected screen size/resolution or settings.