How to put GridView on a multiple row/column Grid? - xaml

I have a GridView(each contains a image and a text), which uses DataTemplate. And my Grid is divided into 30 grid-rows and 40 grid-columns via codes like below. I attached a picture to show my case, please check it.
<RowDefinition Height="*" />
<RowDefinition Height="*" />
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
There is total 25 GridView items (image + text for each), depends on the binding data. And I need to put these 25 items onto 3 rows, e.g. each item will occupy 5 grid-rows and 4 grid-columns.
My question is:
(1)how to specify location of each GridView item?
Below code will make all the GridView items occupy the whole App Layout, but do not make it align as I want.
(2)The whole layout should support scroll horizontally. That is, when swipe the layout to left, the new icons(image+text) hidden on the right side will be shown.
How to achieve it?
<GridView ItemsSource="{x:Bind Skills}"
IsItemClickEnabled="True"
ItemClick="GridView_ItemClick"
ItemTemplate="{StaticResource SkillDataTemplate}"
Grid.Row="0" Grid.RowSpan="30" Grid.Column="0" Grid.ColumnSpan="40"
>
</GridView>

Related

FlipView shows only first Items

I have some code similar to this:
<FlipView UseTouchAnimationsForAllNavigation="False" ItemsSource="{Binding Records}" SelectedItem="{Binding Record, Mode=TwoWay}">
<FlipView.ItemTemplate>
<DataTemplate x:DataType="Models:Record">
<TextBlock x:Name="debugText" Text="{x:Bind Name}" />
<UC:MyControl Record="{x:Bind Mode=OneWay, Converter={StaticResource myConverter}}" />
</DataTemplate>
</FlipView.ItemTemplate>
</FlipView>
MyControl needs the date to be converted with myConverter, and then it shows the detail information of Record. It shows an image, the name, etc.
The TextBlock debugText is created for debugging purposes.
When I move the FlipView by hand or by code, the elements are transitioning correctly. I can debug how the SelectedItem is updated correctly, and I can see the debugText updating correctly.
But for some reason, MyControl cycling between the first items. It is showing only the 3 or 4 first items, and after arriving at 3th or 4th, it starts again showing the first one. I debug the converter myConverter, and I can see that it is called 3 or 4 times loading the view. But then it not called anymore, even when I transition to the next elements.
It shows only the 3 first elements when UseTouchAnimationsForAllNavigation="False", and it shows the 4 first elements when UseTouchAnimationsForAllNavigation="True".
I can manage to show all the items correctly, by writting the FlipView.ItemsPanel:
<FlipView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel AreScrollSnapPointsRegular="True" Orientation="Horizontal" />
</ItemsPanelTemplate>
</FlipView.ItemsPanel>
But it is not a solution for me, because there are many Records (can be more than 300), and done in this way the page takes so long in loading, and wastes so much memory. When I run it in this mode in a phone, the application even crashes when there are many records.
How can I make it work for more than the 3 or 4 first items?

how (and where) do I get actual ColumnDefinition Width="*"

Short version of what I'm trying to accomplish.
Have a scrollable grid with a button.
Once button is pressed inject two buttons to the right of the existing row content and scroll the content horizontally to the left so that the right edge of the second button injected into the layout is aligned with the right edge of the screen.
Longer version describing the solution tried and the problems encountered:
I have a custom control (grid inside a scrollview) for a row in ListView.
Normally that grid is the same width as the device.
The star of the show is
< ColumnDefinition Width="*" x:Name="Star"/>
<Label Grid.Row="2" Grid.Column="3" Text="{Binding FacebookId}" x:Name="IDLabel"
Style="{StaticResource SmallLabelStyle}"
HorizontalOptions="Fill"
VerticalOptions="StartAndExpand" BackgroundColor="Red"
/> is assigned to that column later on in xaml
last two columns in the grid for delete and block buttons are initially zero width
<ColumnDefinition Width="0" x:Name="cdDelete"/>
<ColumnDefinition Width="0" x:Name="cdBlock"/>
and, hence, not shown (to have the * column hosting the label to be sized properly, because, besides the label, there is a thumbnail, a button and spacing columns present in the grid)
prior to those two there is a column for a button that changes the
columns width and scroll the expanded grid within the scrollview.
So I need some way to replace the gridLength for ColumnDefinition "*"
with the actual Width of that column for the device I run on.
this.cdBlock.Width = this.cdDelete.Width = Metrics.ThumbnailDiameter;
if (starwidth <= 0)
{
starwidth = this.IDLabel.Width;
^^^^^^^^^^^^^^^^^^^^^^^^^ problem is here: this returns the width the label fits into, not the actual width of the label highlighted (see red background above)
}
this.Star.Width = new GridLength(starwidth);
any suggestions how to deal with this?
Thanks.
It seems that ViewCell.ContextActions can be used to leverage
the platform table editing functionality
Which means the button exposing delete/block buttons would have to go
unless there is a way to show buttons for contextactions programmatically

ComboBox which is bound to a db table should initially be blank

I have a WPF combobox control bound to a edm field in a database table. This works fine except that it enters the first value in the control when it starts which is not wanted. Heres the xaml
<ComboBox x:Name="cbMeasure"
Width="104"
ItemsSource="{Binding Source={StaticResource ddMeasureViewSource}}"
DisplayMemberPath="Measure"
IsSynchronizedWithCurrentItem="True"
SelectedValuePath="Measure"
SelectedValue="{Binding Measure1}"/>
If I just hard code the control it doesn't put the first value in the variable. Heres what that xaml looks like
<ComboBox x:Name="cbMeasure" Width="104" Text="{Binding Measure1}">
<TextBlock Text="one"/>
<TextBlock Text="two"/>
<TextBlock Text="three"/>
<TextBlock Text="four"/>
</ComboBox>
What do I have to do to make the database bound combobox start with an empty value the way the textbox combobox does? This is a problem as it puts the first value in the SelectedValue bound to a variable (Measure1).
The db table ddMeasure looks like:
RID Measure
--- -------
1 One
2 Two
3 Three
4 Four
so "One" in put into the ComboBox selection and Measure1 variable is populated as well.
OK I found the solution to this. You have to set the property IsSynchronizedWithCurrentItem to false which I thought I had tried but I think I just removed that property and the default must be true. So the xaml looks like
<ComboBox x:Name="cbMeasure"
Width="104"
ItemsSource="{Binding Source={StaticResource ddMeasureViewSource}}"
DisplayMemberPath="Measure"
IsSynchronizedWithCurrentItem="False"
SelectedValuePath="Measure"
SelectedValue="{Binding Measure1}"/>
Hope this helps others who try to find info on this type of binding.

How to make a cell in a datagrid readonly based the content on another cell in SL4?

I have two columns, the second column depends on the content on the first column. By default, the second columns is readonly. When I enter some valid value, I want the second column to become editable.
To achive this, I created a cell template and cell edit template on the second column where back ground and read only bound to the first column. On load, the first column is null so my second columns comes correctly as read only. Following is Cell Template for second column, where the background color is set by based on the first column.
<DataTemplate>
<Grid>
<Border Background="{Binding FristColumn,Converter={StaticResource ColorConverter}}"/>
<TextBlock Text="{Binding SecondColumn, Converter={StaticResource NumberFormatter}}" HorizontalAlignment="Stretch" VerticalAlignment="Center" Margin="0"/>
</Grid>
</DataTemplate>
Following is cell edit template for second column to make it editable
<DataTemplate>
<Grid>
<TextBox Text="{Binding SecondColumn, Mode=TwoWay, Converter={StaticResource NumberFormatter}}" Margin="0" HorizontalAlignment="Right" IsReadOnly="{Binding FirstColumn, Converter={StaticResource readOnlyConverter}, ConverterParameter=FirstColumn}" Background="{Binding Depend,Converter={StaticResource ColorConverter}, ConverterParameter=FirstColumn}" />
</Grid>
</DataTemplate>
With these two in place, when enter the valid value in the first column, I was expecting the second column color to change but it does not. But If I double click on the cell then it behaves properly based on the first cell. Is there some thing I am missing?
The problem was, the object collection did not have INotifyPropertyChanged implemented. Once I have INotifyPropertyChanged implemented, the colors and cell become editable and non editable based on the converter.
Hope this helps others.

Multicolumn display combobox within WPF datagrid

I wanted to create custom WPF datagrid control, which allows to have datagridcomboboxcolumn with multicolumn display on selection of combobox, how this can be implemented. Please help
Thanks in advance
Kartheesh.
I'm a little confused to exactly what your trying to ask, but possibly I think it's either of two things;
You want a multi-column display per column. For example you want two or more items per column displayed, e.g. two checkboxes, or textboxs, etc. The following code below displays two combox boxes binded to an object data provider
<dg:DataGridTemplateColumn >
<dg:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding item1}" />
<TextBlock Text="{Binding item2}" />
</StackPanel>
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
<dg:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox ItemsSource="{StaticResource mybiglist}"
SelectedValue="{Binding item1}"/>
<ComboBox ItemsSource="{StaticResource mysecondbiglist}"
SelectedValue="{Binding item2}"/>
</DataTemplate>
</dg:DataGridTemplateColumn.CellEditingTemplate>
</dg:DataGridTemplateColumn>
Alternatively perhaps you want one or more columns per combo box, then this should help;
Multi-Column ComboBox in WPF
A Simple Multicolumn Combo Box in WPF