WPF滑块控件的DataBinding Tick属性 [英] DataBinding Tick Property of WPF slider control
问题描述
我正在尝试探索滑块控件.目前,我需要将滑块控件用作导航控件.为此,我想将滑块控件的Tick属性数据绑定到集合.
Ticks属性是一个依赖项属性,因此它应该能够接受绑定.
这就是我在做什么.
我有一个带有List< Object>的类myCollectionClass.物业
I am trying to explore the slider control. Currently I have a requirement to use the slider control as navigation control. For that I want to databind the Tick property of the slider control to a collection.
The Ticks property is a dependency property and so it should be able to accept bindings.
This is what I am doing.
I have a class myCollectionClass with a List<Object> Property
public List<double> myCollection
{
get
{
List<double> myList = new List<double>();
myList.Add(1);
myList.Add(2);
myList.Add(3);
myList.Add(4);
return myList;
}
}
我想将壁虱数据绑定到myCollection
这就是我在XAML中所做的
I want to databind the ticks to myCollection
This is what I have done in XAML
<Window.Resources>
<c:myCollectionClass x:Key="CollClass"/>
</Window.Resources>
<Grid DataContext="{StaticResource CollClass}">
<StackPanel Grid.Row="1">
<Slider TickPlacement="BottomRight"
IsSnapToTickEnabled="True"
Ticks="{Binding myCollection}"/>
</StackPanel>
</Grid>
这不起作用.
如果我说-
This does not work.
If I say -
<Slider TickPlacement="BottomRight"
IsSnapToTickEnabled="True"
Ticks="1,2,3,4,5"/>
它工作正常,但我正在尝试将Ticks绑定到该集合.
知道如何实现吗?
it works fine, but I am trying to bind the Ticks to the collection.
Any idea how to achieve this?
推荐答案
在我看来,Ticks接受DoubleCollection类型的值.
我尝试手动进行操作,发现Ticks不能接受Type List的值.
所以我认为您可以替换List< double>与DoubleCollection.基本上,DoubleCollection是非泛型的,并且仅采用数据类型Double的值以及其OrderedCollection!
因此属性应如下所示:
In my opinion, the Ticks takes values of type DoubleCollection.
I tried doing it manually and found that Ticks cannot take values of Type List.
So what i think is that you can replace the List<double> with DoubleCollection. Basically DoubleCollection is non-generic and takes only values of Datatype Double and also its an OrderedCollection!
So the property should be like this:
public DoubleCollection myCollection
{
get
{
DoubleCollection myList = new DoubleCollection();
myList.Add(1);
myList.Add(2);
myList.Add(3);
myList.Add(4);
return myList;
}
}
希望对您有所帮助!
Hope it helped!
这篇关于WPF滑块控件的DataBinding Tick属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!