我的應用程序(MVVM Light)調整它的主窗口(隱藏並用動畫顯示它)。對於動畫我使用StaticResources帶參數的DataTrigger:如何將StaticResources傳遞給MVVM中的ViewModel?
<Window.Resources>
<system:Double x:Key="WindowMaxWidth">400</system:Double>
<system:Double x:Key="WindowMinWidth">25</system:Double>
</Window.Resources>
<Window.Style>
<Style TargetType="Window">
<Style.Triggers>
<DataTrigger Binding="{Binding DropBox.IsShown}" Value="True">
<DataTrigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Width"
To="{StaticResource WindowMaxWidth}"
Duration="0:0:0:0.2"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.EnterActions>
<DataTrigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Width"
To="{StaticResource WindowMinWidth}"
Duration="0:0:0:0.2"/>
</Storyboard>
</BeginStoryboard>
</DataTrigger.ExitActions>
</DataTrigger>
</Style.Triggers>
</Style>
</Window.Style>
在我的ViewModel我需要我的窗口的寬度值,所以我約束它。問題是它默認爲0,所以我必須用一個值來初始化它。其實什麼需要是我的靜態資源的價值:WindowMaxWidth。
- 我不能WindowMaxWidth的價值轉移到視圖模型,因爲DataTriggr不接受綁定(它抱怨線程)
- 我不想在StaticResources和視圖模型分別保持相同的值,以避免不連貫。
我該怎麼辦?