简体   繁体   English

如何在 xaml 中继承用 C# 编写的自定义控件

[英]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.

相关问题 如何在c#中将文本块属性继承到自定义控件 - How to inherit a textblock properties to a custom control in c# 如何将此 xaml 转换为 C#? - How do I convert this xaml to C#? 如何使用XAML / C#向Windows应用商店应用中的控件(框/网格)添加“DropShadow”效果? - How do I add a 'DropShadow' effect to a control (box/grid) in a Windows Store App using XAML/C#? 如何使用户控件显示为在Windows 8.1 C#和XAML中弹出 - How do I make a user control display as pop up in windows 8.1 c# and xaml 将UniformToFill与图像一起使用时,如何在C#或XAML中控制剪裁 - How do I control clipping in C# or XAML when using UniformToFill with an image 自定义控件XAML中的C#WPF参考自定义属性值 - C# WPF reference custom property value inside custom control xaml 如何在FlipView中访问XAML DataTemplate内部的图像控件 - How do I access a image control inside a XAML DataTemplate in a FlipView 如何访问XAML DataTemplate中的控件? - How do I access a control inside a XAML DataTemplate? 如何在另一个项目中使用自定义WPF / XAML控件? - How do I use a custom WPF/XAML control in another project? 如何从用C#编写的抽象基类继承 - How to inherit from an abstract base class written in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM