2012-07-22 49 views
0

我有以下的DataTemplate如何ItemsControl中的DataTemplate中獨立的ItemsControl的特定屬性綁定

 <DataTemplate x:Key="iconButtonsTemplate"> 
      <StackPanel Orientation="Horizontal" Margin="120,50,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" > 
       <icon:IconButton Command="{Binding Path=DataContext.ButtonClickCommand,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" 
            CommandParameter="{Binding Path=CommandParameter}" TextContent="{Binding TextContent}" ImageSource="{Binding ImageSource}" 
            IsIconButtonVisible="{Binding Path=MyLocalBoolList}" /> 
      </StackPanel> 
     </DataTemplate> 

而且我也ItemsControl中使得

 <ItemsControl Width="2400" VerticalAlignment="Top" HorizontalAlignment="Left" 
          ItemsSource="{Binding IconConfigList}" ItemTemplate="{StaticResource iconButtonsTemplate}" > 
       <ItemsControl.ItemsPanel> 
        <ItemsPanelTemplate> 
         <WrapPanel Orientation="Horizontal"/> 
        </ItemsPanelTemplate> 
       </ItemsControl.ItemsPanel> 
     </ItemsControl> 

所以是有可能結合我ItemsControl中獨立於IconConfigList的ViewModel的IsIconButtonVisible屬性。

+0

爲什麼你有這個屬性,當有'可見性'?我也不知道你最後一句話(和那個問題)應該是什麼意思。 – 2012-07-22 22:49:54

+0

我的知名度也與IconButton中的特殊動畫有關。我的目的是在運行時爲每個圖標處理IsIconButtonVisible。所以我想要一個單獨的列表來更新每個圖標的IsIconButtonVisible屬性 – ugurkaya 2012-07-22 22:53:05

+0

該信息屬於IconConfigList的項目,爲什麼要將它分開? – 2012-07-22 22:55:03

回答

0

在綁定中使用ElementName值。

<DataTemplate x:Key="iconButtonsTemplate"> 
    <StackPanel Orientation="Horizontal" Margin="120,50,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" > 
     <icon:IconButton Command="{Binding Path=DataContext.ButtonClickCommand,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}" 
        CommandParameter="{Binding Path=CommandParameter}" TextContent="{Binding TextContent}" ImageSource="{Binding ImageSource}" 
        IsIconButtonVisible="{Binding Path=DataContext.MyLocalBoolList, ElementName=ItemsControlName}" /> 
    </StackPanel> 
</DataTemplate> 

如果ElementName不適用於您,請嘗試使用RelativeSource。

0
IsIconButtonVisible="{Binding Path=DataContext.ViewModelProperty,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" 

我希望這會有所幫助。

+0

我試過了,但沒有奏效。謝謝 – ugurkaya 2012-07-23 19:02:14

+0

你想綁定這個屬性的VM屬性的類型是什麼? – ethicallogics 2012-07-24 01:43:10

+0

是列表類型 ugurkaya 2012-07-24 05:42:09

相關問題