Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It's actually possible, however quite tricky.</p> <p>My example works without any code-behind, actually without any value converters, too.</p> <p>Here is the code: (now simplified version, thanks to @H.B. for ideas)</p> <pre><code>&lt;Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"&gt; &lt;Page.Resources&gt; &lt;Style x:Key="RBToggleButtonStyle" TargetType="RadioButton"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate&gt; &lt;ToggleButton IsChecked="{Binding IsChecked, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" Content="{Binding Content, RelativeSource={RelativeSource TemplatedParent}, Mode=TwoWay}" /&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;Setter Property="Width" Value="150"/&gt; &lt;Setter Property="Height" Value="25"/&gt; &lt;Setter Property="HorizontalAlignment" Value="Right"/&gt; &lt;Setter Property="VerticalAlignment" Value="Bottom"/&gt; &lt;Setter Property="Margin" Value="15"/&gt; &lt;Setter Property="Content" Value="Hide"/&gt; &lt;/Style&gt; &lt;Style x:Key="MyBorderStyle" TargetType="Border"&gt; &lt;Style.Triggers&gt; &lt;DataTrigger Binding="{Binding IsChecked}" Value="True"&gt; &lt;Setter Property="Visibility" Value="Hidden"/&gt; &lt;/DataTrigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/Page.Resources&gt; &lt;Grid&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition/&gt; &lt;ColumnDefinition/&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Border Background="Green" Grid.Column="0" Style="{StaticResource MyBorderStyle}" DataContext="{Binding ElementName=greenB}"&gt; &lt;RadioButton x:Name="greenB" GroupName="x" Style="{StaticResource RBToggleButtonStyle}"/&gt; &lt;/Border&gt; &lt;Border Background="Red" Grid.Column="1" Style="{StaticResource MyBorderStyle}" DataContext="{Binding ElementName=redB}"&gt; &lt;RadioButton x:Name="redB" GroupName="x" Style="{StaticResource RBToggleButtonStyle}"/&gt; &lt;/Border&gt; &lt;/Grid&gt; &lt;/Page&gt; </code></pre> <p>The idea of using <code>ToggleButtons</code> is stolen from <a href="https://stackoverflow.com/questions/2362641/how-to-get-a-group-of-toggle-buttons-to-act-like-radio-buttons-in-wpf/5188053#5188053">some other question at SO</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload