0

I have a ItemsControl with an ItemContainerStyle based on ToggleButton. This works just fine at runetime, but it casts an error in the designer. (So I have to comment it out if i want to use the designer) I populate this with code behind. Using RadioButtons.

InvalidOperationException: A style intended for type 'RadioButton' cannot be applied to type 'ContentPresenter'.

Iv lived with this for along time now, but its time to see if there is a solution!

Any ideas how to work around this?

<ItemsControl x:Name="BrushButtons"
              Grid.Row="1"
              Grid.Column="3"
              VerticalAlignment="Bottom">

    <ItemsPanelTemplate>
        <StackPanel VerticalAlignment="Bottom" Orientation="Vertical" />

    </ItemsPanelTemplate>
    <ItemsControl.ItemContainerStyle>
        <Style BasedOn="{StaticResource {x:Type ToggleButton}}" TargetType="{x:Type RadioButton}">
            <Setter Property="LayoutTransform">
                <Setter.Value>
                    <RotateTransform Angle="-90" />
                </Setter.Value>
            </Setter>
            <Setter Property="Width" Value="70" />
        </Style>
    </ItemsControl.ItemContainerStyle>
</ItemsControl>

Kind Regards.

2
  • The items container of an ItemsControl is a ContentPresenter, so your ItemContainerStyle should target ContentPresenter. Instead of populating the control with RadioButtons in code behind, you should define an ItemTemplate with a RadioButton. Commented Aug 9, 2016 at 8:01
  • Okey, Thank you for your response. Will try to rewrite it. Commented Aug 16, 2016 at 5:21

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.