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>
精彩评论