2012-11-29 89 views
3

也許我還有另一個無法解決的問題。在Silverlight XAML中,我無法通過StyleSlider.Minimum屬性設置負值。我的意思是,這是可能的,但結果是意想不到的。在WPF中,這確實工作正常。Slider.Minimum屬性負值問題

<StackPanel Width="200" Orientation="Vertical"> 
    <StackPanel.Resources> 
     <Style TargetType="Slider" x:Key="style"> 
      <Setter Property="Minimum" Value="-10" /> 
      <Setter Property="Maximum" Value="10" /> 
      <Setter Property="Value" Value="0" /> 
     </Style> 
    </StackPanel.Resources> 
    <!-- Here it is not working --> 
    <Slider Style="{StaticResource style}"/> 
    <!-- Here it works as expected, as it is not styled --> 
    <Slider Minimum="-10" Maximum="10" Value="0" /> 
</StackPanel> 

的結果是這樣的:

enter image description here

但很明顯的兩拇指應該是在同一個位置(在Slider中間)。

事實上,它看起來就像Minimum值(-10)接受,但後來Maximum值變爲0,這就是爲什麼第一個滑塊有對齊到右側拇指(Value是0和Maximum也是0)。

+0

問題不在於滑塊屬性'Minimun',而是屬性'Maximum',導致在樣式中設置的值沒有得到應用。 – Jehof

+0

是的,我在我的帖子末尾寫了這個,但它仍然只出現在負數「最小」的情況下。 – infografnet

+0

我已經更新了我的答案 – Jehof

回答

2

問題是Slider的HorizontalTemplate。如果將Slider的Orientation更改爲Vertical,則樣式中定義的值將按預期應用。

更新: 解決方案是也設置風格的方向。然後它按預期工作。

<Style TargetType="Slider" x:Key="style"> 
    <Setter Property="Minimum" 
      Value="-10" /> 
    <Setter Property="Maximum" 
      Value="10" /> 
    <Setter Property="Value" 
      Value="0" /> 
    <Setter Property="Orientation" 
      Value="Horizontal" /> 
</Style> 
+0

確定嗎?你使用哪個設計師?我使用Visual Studio 2010.您的提案沒有改變我的環境中的任何內容。但是我注意到另一個東西:如果我手動應用'Maximum =「10」'到一個樣式化滑塊(''),「Thumb」正確的位置,然後我刪除這個('最大=「10」'),'拇指'不會回到右側(留在中間),直到我重新加載設計器中的xaml。如果您使用解決方案重新加載設計器會發生什麼?它仍然有效嗎? – infografnet

+0

@infografnet我正在使用Visual Studio 2012。 – Jehof