作为 RadioToggleButton 的 WPF 自定义用户控件
我创建了一个自定义用户控件,其功能类似于单选按钮,但看起来像切换按钮。我遇到的唯一问题是能够设置 UserControl 的 Content 属性并将其显示在 ToggleButton 中。这是我尝试过的:
<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>
当我尝试构建它时,我收到错误:“无法在“Control”类型上找到静态成员“ContentProperty”。”我整个早上都在思考这个问题,虽然我尝试模仿一些例子,但到目前为止还没有成功。有什么想法吗?
I've 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
知道了:
Got it: