UNO DataGrid Template Columns - RadioButton - uno-platform

In general, we are able to use the Uno DataGrid with the help of UNO.CommunityToolkit.WinUI.UI.Controls
But for templated columns with Radio Button, it fails to build with the below message.
Couldn't find any example the sample
System.InvalidOperationException: The type {using:CommunityToolkit.WinUI.UI.Controls}DataGridRadioButtonColumn could not be found
<controls:DataGrid.Columns>
<controls:DataGridTemplateColumn Header="Scanned" Width="60">
<controls:DataGridTemplateColumn.CellTemplate>
<controls:DataTemplate>
<RadioButton IsChecked="False" "GroupName="{Binding DisplayName}" Margin="5,0" HorizontalAlignment="Center" />
</controls:DataTemplate>
</controls:DataGridTemplateColumn.CellTemplate>
</controls:DataGridTemplateColumn>
<controls:DataGrid.Columns>
Have also tried using the below, but still fails:
<controls:DataGrid.Columns>
<controls:DataGridTextColumn Header="Rank"/>
<controls:DataGridRadioButtonColumn Header="Mountain"/>
</controls:DataGrid.Columns>

Related

How to set a control in XAML visible if another control is visible on the same page

I have a card in Xamarin Forms that I want to be visible only if a button is visible as well. For some reason the same IsVisible attribute for the button isn't working for the card, so is there a way for me to say if the button is visible, let the card be visible?
<cor:BindableToolbarItem x:Name="Inside"
Command="{Binding InsideCommand}"
IsVisible="{Binding SelectedReading.Inside, Converter={StaticResource valueIsNotNull}}"
Icon="hi.png"
Order="Primary" />
That's the button on the toolbar:
<controls:InsideCard
BindingContext="{x:Reference Inside}"
IsVisible="{Binding SelectedReading.Inside, Converter={StaticResource valueIsNotNull}}">
</controls:InsideCard>
As you can see the IsVisible is the same for both, but it isn't working, so I tried referencing the button inside the card but it doesn't work obviously. How can I do it properly?
The BindingContext is set to the Inside element hence the SelectedReading.Inside property will not be available in the Inside object. Hence the binding won't work. Bind the IsVisible property of Inside.
<controls:InsideCard BindingContext="{x:Reference Inside}" IsVisible="{Binding IsVisible}"/>
Or set the source of binding to {x:Reference Inside} in Binding markup itself.
<controls:InsideCard IsVisible="{Binding IsVisible, Source={x:Reference Inside}}"/>
Just to add:
Moreover binding same property to two different Views should work too (If you are setting it in ViewModel). Or also setting Mode as TwoWay for Inside element. For both the cases you must have implemented the NotifyPropertyChanged for the binded property of ViewModel.
<Label
x:Name="label1"
IsVisible="{Binding ViewVisiblity}"
Text="Hi there"/>
<Label
x:Name="label2"
Text="Hi there2"
IsVisible="{Binding ViewVisiblity, Mode=TwoWay}"/>

Devexpress silverlight grid header checkbox column

Is it possible to select or deselect the check box ( silverlight devexpress grid check box ) based on Grid header checkbox column , using client side events or server side events.
Sample Code :
<dxg:GridControl.View>
<dxg:TableView NavigationStyle="Cell" VerticalContentAlignment="Top" AllowColumnFiltering="True" AllowFilterEditor="True" ShowTotalSummary="True" Foreground="Black" ShowGroupPanel="False" AllowEditing="False" >
</dxg:TableView>
</dxg:GridControl.View>
<dxg:GridControl.Columns>
<dxg:GridColumn FieldName="EID" Fixed="Left" Width="70" VerticalAlignment="Top" AllowFocus="False" FilterPopupMode="CheckedList"></dxg:GridColumn>
<dxg:GridColumn FieldName="EN" Header="Name" Width="180" AutoFilterCondition="Contains" Fixed="Left" VerticalAlignment="Top" AllowFocus="False" FilterPopupMode="CheckedList" />
<dxg:GridColumn FieldName="DOJ" Header="Date Of Joining" Width="110" AllowFocus="False" FilterPopupMode="CheckedList" />
<dxg:GridColumn FieldName="CEX" Width="170" Visible="True" AutoFilterCondition="Like" AllowFocus="False" FilterPopupMode="CheckedList" />
<dxg:GridColumn FieldName="CheckBoxColumn" Width="170" Visible="True" AutoFilterCondition="Like" AllowFocus="False" FilterPopupMode="CheckedList" />
</dxg:GridControl.Columns>
<dxg:GridControl.GroupSummary>
<dxg:GridSummaryItem SummaryType="Count" />
</dxg:GridControl.GroupSummary>
<dxg:GridControl.TotalSummary>
<dxg:GridSummaryItem FieldName="EID" ShowInColumn="EN" SummaryType="Count"/>
</dxg:GridControl.TotalSummary>
</dxg:GridControl>
You have to modify the cell template in order to achieve what you want.
It will be something like this:
<dxg:GridColumn VisibleIndex="38" Header="h1" FieldName="h1" Name="h1">
<dxg:GridColumn.CellTemplate>
<DataTemplate>
<dxe:CheckEdit IsChecked="True" HorizontalAlignment="Center">
</dxe:CheckEdit>
</DataTemplate>
</dxg:GridColumn.CellTemplate>
</dxg:GridColumn>
After creating the new template you can access your Column and load its content in order to modify the element within it:
var checkBox = MyGrid.Columns["h1"].CellTemplate.LoadContent() as DevExpress.Xpf.Editors.CheckEdit
Then
checkBox.IsChecked = true
Hope it helps!

WP7 Databinding to Listbox from code with DataTemplate

Here is the XAML i use to display the Listbox:
<ListBox x:Name="groupedList" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
<ListBox.ItemTemplate>
<DataTemplate x:Name="myTemplate">
<StackPanel Orientation="Vertical">
<TextBlock Grid.Row="0" FontWeight="Bold" x:Name="templateHeader" />
<TextBlock Grid.Row="1" x:Name="templateCaption"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
The problem is that the Databinding has to be created in code since there is different data each time. (In fact the data comes by using an indexer[] with a dynamically selected field in a sql). My question now is how to apply the Databinding to the Listbox and the DataTemplate from code. As far as i can see there is no way access the items defined inside of a DataTemplate.... Can anyone help ?
This is my attempt so far:
Binding binding = new Binding("["+CaptionField+"]");
binding.Source = this.controller.table.Rows;
binding.Mode = BindingMode.TwoWay;
BindingOperations.SetBinding(this.groupedList.Items, ItemsControl.ItemsSourceProperty, binding);
this.groupedList.SetBinding(null, binding);
I was about to give you a simple example but I think there are plenty of better example, so please take a look at these site to see if it help:
WP7 - listbox Binding
listbox-data-binding
Please comment if anything wasn't clear.

Getting value of "System.Windows.Controls.TextBlock" when binding to Silverlight ComboBox

I'm attempting to use a Silverlight ComboBox with a static list of elements in a very simple binding scenario. The problem is the selected item is not returning me the Text of the TextBlock within the ComboBox and is instead returning "System.Windows.Controls.TextBlock".
My XAML is:
<ComboBox SelectedValue="{Binding Country, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}">
<TextBlock FontSize="11" Text="Afghanistan" />
<TextBlock FontSize="11" Text="Albania" />
<TextBlock FontSize="11" Text="Algeria" />
</ComboBox>
In my C# file I'm binding to the ComboBox using:
Customer customer = new Customer() { Country = "Albania" };
DataContext = customer;
The binding does not result in Albania as the selected country and updating the ComboBox choice results in the Country being set to "System.Windows.Controls.TextBlock". I've tried fiddling around with DisplayMemberPath and SelectedValuePath but haven't found the answer. I suspect it's something really simple I'm missing.
Changing the ComboBox items to strings works. I'm not sure how you'd go about handling the case where TextBlocks were required for formatting...
<ComboBox SelectedValue="{Binding Country, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}">
<System:String>Afghanistan</System:String>
<System:String>Albania</System:String>
<System:String>Algeria</System:String>
</ComboBox>

silverlight datagrid multicontrol TemplateColumn TabIndex issue

In SL4 DataGrid I have the following multicontrol column:
<sdk:DataGridTemplateColumn Header="Address Line1
Address Line 2" MinWidth="200">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Path=Address1}"/>
<TextBlock Text="{Binding Path=Address2}"/>
</StackPanel>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
<sdk:DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<StackPanel>
<TextBox Background="Transparent" BorderThickness="0"
TabIndex="0"
Text="{Binding Path=Address1, Mode=TwoWay}"/>
<TextBox Background="Transparent" BorderThickness="0"
TabIndex="1"
Text="{Binding Path=Address2, Mode=TwoWay}"/>
</StackPanel>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellEditingTemplate>
</sdk:DataGridTemplateColumn>
In edit mode pressing Tab key while at address1 moves focus to next DataGrid column but not to address2 textbox. If I delete CellTemplate and CellEditingTemplate to be CellTemplate instead, then TabIndex works as expected, however, current column stay the same, so if datagrid has many columns, some of which are hidden, then auto scrolling doesn't occur. What should I do to solve this problem?
A little bit late, but i found a workaround for this problem.
Just add a KeyDown EventHandler to your CustomControl:
private void address1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key.Equals(Key.Tab) && address2.IsEnabled)
{
address2.Focus();
e.Handled = true;
}
}
Probably, having multiple controls inside datagrid cell is bad idea. If multiple controls needs to be inside cell, then better way seems to be to create custom composite control and place it inside cell.

Resources