2011-09-11 53 views
1

我想使用下面的用戶控件進行三種不同的演示。因爲是在通過數據上下文對象具有共同的接口,唯一的兩件事情,將從每一呈現變化將是:用戶控制重構 - 我能做得比這更好嗎?

  1. 圖像資源(「imgDepartment」)
  2. 的FilterPanel控制(EmployeeFilterPanel)

就這樣,僅僅因爲這兩個項目,我需要這個用戶的三個單獨版本,其中大部分都是重複的代碼。

我可以這樣做嗎?怎麼樣?

乾杯,
Berryl

<DockPanel LastChildFill="True" > 
    <uc:ListSubjectHeader DockPanel.Dock="Top" 
     Subject="{Binding PresentationSubject}" 
     AddNewItemCommand="{Binding AddCommand}" 
     ImageSource="{StaticResource imgDepartment}" 
          /> 
    <local:EmployeeFilterPanel DockPanel.Dock="Top" DataContext="{Binding MasterVm}"/> 

    <Grid Margin="0, 5, 0, 0"> 
     <common:MasterListingWorkspacesControl /> 
    </Grid> 

</DockPanel> 

enter image description here

更新

解決了建立風格和下面添加一個PresentationImageUri屬性,我的視圖模型圖像部分:

<Style x:Key="ListSubjectHeaderStyle" TargetType="{x:Type uc:ListSubjectHeader}"> 
    <Setter Property="DockPanel.Dock" Value="Top" /> 
    <Setter Property="Subject" Value="{Binding PresentationSubject}" /> 
    <Setter Property="AddNewItemCommand" Value="{Binding AddCommand}" /> 
    <Setter Property="ImageSource" Value="{Binding PresentationImageUri}" /> 
</Style> 

還不確定如何處理該FilterPanel類型。

回答

0

我不想回答我自己的東西,但也許它會幫助別人。我在我的視圖模型中結合使用了DataTemplates,一個資源轉換器和一個字符串鍵。更多詳細信息和一些代碼here

B

0

爲什麼不把ImageSource的 & 的DataContext通過代碼隱藏?

相關問題