开发者

WPF Custom UserControl as a RadioToggleButton

开发者 https://www.devze.com 2023-02-10 10:13 出处:网络
I\'v开发者_JS百科e created a custom UserControl that functions like a RadioButton but looks like a Toggle Button. The only issue I\'m having is being able to set the Content property of the UserContro

I'v开发者_JS百科e created a custom UserControl that functions like a RadioButton but looks like a Toggle Button. The only issue I'm having is being able to set the Content property of the UserControl and have it appear in the ToggleButton. Here's what I've tried:

    <UserControl.ContentTemplate>
        <DataTemplate>
            <RadioButton>
                <RadioButton.Template>
                    <ControlTemplate>
                        <ToggleButton IsChecked="{Binding IsSelected, Mode=TwoWay, 
                                RelativeSource={RelativeSource TemplatedParent}}" 
                                      Content="{TemplateBinding Content}"/>
                    </ControlTemplate>
                </RadioButton.Template>
            </RadioButton>
        </DataTemplate>
    </UserControl.ContentTemplate>

When I try to build this, I get the error: "Cannot find the static member 'ContentProperty' on the type 'Control'." I've been hung up on this all morning, and while I've tried to mimic a few examples, so far nothing has done the trick. Any ideas?


Got it:

<UserControl.ContentTemplate>
    <DataTemplate>
        <RadioButton Content="{TemplateBinding UserControl.Content}">
            <RadioButton.Template>
                <ControlTemplate>
                    <ToggleButton IsChecked="{Binding IsSelected, Mode=TwoWay, 
                            RelativeSource={RelativeSource TemplatedParent}}" 
                                  Content="{TemplateBinding UserControl.Content}"/>
                </ControlTemplate>
            </RadioButton.Template>
        </RadioButton>
    </DataTemplate>
</UserControl.ContentTemplate>
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号