[英]How do I inherit a custom control written in C# inside of xaml
I have a problem where a WPF slider is not functioning properly inside a scrollviewer.我有一个问题,即 WPF 滑块在滚动查看器中无法正常运行。 I believe this problem has been adressed here:
我相信这里已经解决了这个问题:
Slider \\ ScrollViewer in a touch interface not working properly 触摸界面中的 Slider \\ ScrollViewer 无法正常工作
The accepted answer is telling to retemplate the slider based on the custom thumb (created in ac# class).接受的答案是根据自定义拇指(在 ac# 类中创建)重新模板化滑块。
Unfortunately whatever I do, I get problems.不幸的是,无论我做什么,我都会遇到问题。
to make things more difficult my slider is based on Mahapps and I found the slider style online:为了让事情变得更困难,我的滑块基于 Mahapps,我在网上找到了滑块样式:
https://github.com/robertbaker/Metro/blob/master/MahApps.Metro/Styles/Controls.Slider.xaml https://github.com/robertbaker/Metro/blob/master/MahApps.Metro/Styles/Controls.Slider.xaml
So, I copied the entire Slider style into my App.Xaml.因此,我将整个 Slider 样式复制到我的 App.Xaml 中。 So far things work...
到目前为止,一切正常……
But When I try to modify the Thumb style by doing a "BasedOn":但是当我尝试通过执行“BasedOn”来修改 Thumb 样式时:
<Style x:Key="HorizontalSliderThumb" TargetType="Thumb" BasedOn="{StaticResource CustomThumb}">
Nothing works....什么都行不通....
I don't know what I'm doing wrong.我不知道我做错了什么。
Help is appreciated !帮助表示赞赏!
Thank you,谢谢,
Just add this to your xaml file只需将其添加到您的 xaml 文件中
xmlns:custom="clr-namespace:<Namespace of custom controls>">
From there you can use从那里你可以使用
<custom:<name of custom component> />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.