I'm very new to XAML and am trying to make 3 radio buttons (1, 2, 3) in a way so that when I press one of them it changes the value of an int x to its according value
this should explain what I mean
<RadioButton Content="{sd:Localize 1, Context=Button}"/> // when checked i want the value of x to become 5
<RadioButton Content="{sd:Localize 2, Context=Button}"/> // when checked i want the value of x to become 6
<RadioButton Content="{sd:Localize 3, Context=Button}"/> // when checked i want the value of x to become 7
is there a clean and MVVM-friendly way of achieving this ?
Thanks In Advance!
One way of achieving this could be:
On your Viewmodel add a command to update value of your property X
Bind the command to your RadioButton and specify a parameter that will be sent to your command.
<RadioButton Command="{Binding UpdateValue}">
<RadioButton.CommandParameter>
<system:Int32>1</system:Int32>
</RadioButton.CommandParameter>
</RadioButton>
Related
I have to create a control which aligns some of its button on the left and some others on the right in one row.
I've immediatly thinked to WPF Toolbar so I've typed:
...
<ToolBarTray DockPanel.Dock="Top">
<ToolBar ToolBarTray.Locked="True" Width="{Binding ElementName=Tray, Path=ActualWidth}">
<DockPanel>
<ToolBarPanel DockPanel.Dock="Left">
<Button ...>
</ToolBarPanel>
<ToolBarPanel DockPanel.Dock="Right">
<Button ...>
</ToolBarPanel>
</DockPanel>
</ToolBar>
</ToolBarTray>
...
but this didn't work: the buttons with dockpanel.dock = right are just attached on the right of the first ToolBarPanel and, if I've understood something about xaml, this is absolutely correct, that's why I tried forcing the width of the toolbar.
If I use a Grid with a spacing column, the right ToolBarPanel moves correctly to the right, but my control needs to be resized and I guess there's no easy way to assign the correct width to the column.
Is there some easier way to achive my task?
I need to create a CommandBarFlyout with many buttons.
My XAML code:
<StackPanel>
<Button Height="40" Width="40">
<Image Source="/Assets/StoreLogo.png"/>
<Button.Flyout>
<CommandBarFlyout>
<AppBarToggleButton>
<AppBarToggleButton.Icon>
<BitmapIcon UriSource="/Assets/StoreLogo.png"/>
</AppBarToggleButton.Icon>
</AppBarToggleButton>
</CommandBarFlyout>
</Button.Flyout>
</Button>
</StackPanel>
If I copy-paste twelve buttons in CommandBarFlyout - only first eleven are showing.
If I add more buttons - still first eleven shown.
From this document about Commandbarflyout, it mentions:
Unlike CommandBar, primary commands do not automatically overflow to
the secondary commands and might be truncated.
So the reason why only 11 buttons are displayed should be that the actual contents have overflowed the scope of the primary command and were truncated.
If you still want to continue to use CommandBarFlyout, you can also add commands to the SecondaryCommands collection. Or as the document said, to use CommandBar or Flyout.
I want one datetime field's background colour to depend on its value. Like if a certain date is passed, the background changes to red.
Is there a way to make this in XAML?
I know there is no possibility of an "if" condition/instruction, but maybe you guys found some way to implement a similar function.
<Canvas Canvas.Left="893" Canvas.Top="208" Height="25" Width="99" Background="red" Panel.ZIndex="-1"/>
<assembly:FieldControl Canvas.Left="890" Canvas.Top="206" FieldControlType="DateControl" FormField="{x:Null}" Height="25" LabelColumnWidth="0" Refnr="123456789" ShowCaption="False" StateImageAlignment="Hidden" Width="106" FontSize="10" Foreground="DimGray"/>
this is my code so far. The Canvas-Part makes the Background go red.
I also tried to put the background property in the "FieldControl" but there it's useless.
EDIT:
After getting the information, that Data Binding could help me with this problem, i tested it like this:
<TextBox Canvas.Left="890" Canvas.Top="226" Name="Date" Width="99" Height="25" VerticalAlignment="Top" Text="{Binding ElementName=Date, Path = SelectedItem.Content, Mode = TwoWay, UpdateSourceTrigger = PropertyChanged}" Background="{Binding ElementName=Date, Path=SelectedItem.Content}">
But this is not the direction, i need. Do you have maybe any suggestion, how I can use Data binding to solve my problem?
Yes, it is possible. The concept you need to learn is XAML Data Binding.
You can implement the IValueConverter for this.
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/data-binding/converters
You can check the value on binding and return the background color.
how to give different text color for each item of listview in xamarin forms
I have a pivot that I am trying to keep from gaining focus when the user hits the tab key. I immediately tried to set IsTabStop to false. However this wasn't keeping a user from tabbing into the pivot. So I tried testing IsTabStop on two buttons and the behavior was exactly what I expected from the pivot.
Here is my xaml:
<Pivot IsTabStop="False">
<PivotItem Header="Test">
<StackPanel Spacing="10">
<Button Content="Button 1" IsTabStop="True"/>
<Button Content="Button 2" IsTabStop="False"/>
</StackPanel>
</PivotItem>
</Pivot>
Am I missing something here or is there a way around this?
Setting tab index to -1 only makes it first, try something like 1001.. In here they explain the issue you may be having but for RichTextBlock, there are various attributes available for it to set.. https://learn.microsoft.com/en-us/windows/uwp/design/accessibility/keyboard-accessibility
So what i ended up doing is overriding the default style on the pivot. I changed the "HeaderClipper" in the style to have IsTabStop="False", this fixed my problem.
The documentation for the default pivot style can be found at https://msdn.microsoft.com/en-us/library/windows/apps/mt299144.aspx
I am trying to bind a combo box to a property on my ViewModel. The target type is short? and I would like to have null be an option. Basically I would like the value of the first item in the combo box be {x:Null}.
<ComboBox Grid.Row="9" Grid.Column="1" SelectedValue="{Binding Priority}">
<clr:Int16></clr:Int16>
<clr:Int16>1</clr:Int16>
<clr:Int16>2</clr:Int16>
<clr:Int16>3</clr:Int16>
<clr:Int16>4</clr:Int16>
<clr:Int16>5</clr:Int16>
<clr:Int16>6</clr:Int16>
<clr:Int16>7</clr:Int16>
<clr:Int16>8</clr:Int16>
<clr:Int16>9</clr:Int16>
<clr:Int16>10</clr:Int16>
</ComboBox>
Any Suggestions?
If you are using XAML 2009 / .NET 4 then you can use a new syntax for creating generics using XAML.
xmlns="http://schemas.microsoft.com/netfx/2009/xaml/presentation"
<Nullable x:TypeArguments="clr:Int16" />
This article has other, more complex, scenerios for generics in XAML.