简体   繁体   中英

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. I believe this problem has been adressed here:

Slider \\ ScrollViewer in a touch interface not working properly

The accepted answer is telling to retemplate the slider based on the custom thumb (created in ac# class).

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:

https://github.com/robertbaker/Metro/blob/master/MahApps.Metro/Styles/Controls.Slider.xaml

So, I copied the entire Slider style into my App.Xaml. So far things work...

But When I try to modify the Thumb style by doing a "BasedOn":

<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

xmlns:custom="clr-namespace:<Namespace of custom controls>">

From there you can use

<custom:<name of custom component> />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM