2013-04-23 69 views
0

我有一組樣式綁定到viewmodel。這適用於背景和前景。我現在想要綁定字體大小。我可以使綁定工作,但是當我更改該值併爲該屬性調用PropertyChanged時,它不會獲得新值。有任何想法嗎?在Silverlight樣式中綁定FontSize風格不變

sample.xaml

<Style x:Key="ApplicationNameStyle" TargetType="TextBlock"> 
    <Setter Property="Foreground" Value="{StaticResource NavigationForegroundColorBrush}"/> 
    <Setter Property="FontSize" Value="{Binding FontSize12, Source={StaticResource Sampe}}"/> 
    <Setter Property="FontWeight" Value="Bold"/> 
    <Setter Property="Margin" Value="0,2,0,0"/> 
    <Setter Property="VerticalAlignment" Value="Center"/> 
    <Setter Property="Effect"> 
     <Setter.Value> 
      <DropShadowEffect BlurRadius="10" Opacity="0.25" ShadowDepth="0"/> 
     </Setter.Value> 
    </Setter> 
</Style> 

sampleviewmodel.cs

public Double FontSize12 
{ 
    get 
    { 
     return _fontSize12; 
    } 
    set 
    { 
     _fontSize12 = value; 
     if (PropertyChanged != null) 
      PropertyChanged(this, new PropertyChangedEventArgs("FontSize12")); 
    } 
} 
+0

對不起,我無法重現問題。我使用你的樣式設置了一個示例項目,添加了一個示例視圖模型對象,並添加了一個TextBlock,使用你的樣式和一個按鈕,當我點擊它時,在視圖模型對象中的字體大小加2。這表現如預期:每次點擊按鈕時,字體變得越來越大。你試圖設置字體大小的值是什麼? – 2013-04-23 21:01:14

回答

1

你可以嘗試設置你的綁定Mode=TwoWay。這會使對象上的任何更改都反映在UI上。

+0

謝謝你照顧它。 – doclove 2013-04-24 12:34:17