0

I have following DataTemplate

        <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>

And I have also ItemsControl such that ,

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

So is it possible to bind my IsIconButtonVisible property to ViewModel independent from IconConfigList in ItemsControl.

U.Kaya
  • 27
  • 3
  • Why do you have this property when there is `Visibility`? Also i have no idea what your last sentence (and the question for that matter) is supposed to mean. – H.B. Jul 22 '12 at 22:49
  • My visibility is also related with an special animation in IconButton. My purpose is to handle IsIconButtonVisible for each icon during runtime. So I want a separate list to update IsIconButtonVisible properties for each icon – U.Kaya Jul 22 '12 at 22:53
  • That information belongs in the items of the IconConfigList, why would you separate it? – H.B. Jul 22 '12 at 22:55
  • I want to separate because , loading whole list is so heavy and unnecessary. And also , during runtime , I just wanted to update IsIconButtonVisible properties. ( I have tried in IconConfigList , but it was so slow , I have to fasten ) – U.Kaya Jul 22 '12 at 22:59
  • I suspect that you are doing something wrong if that was slow... – H.B. Jul 22 '12 at 23:01
  • Yeah you may right , but we will use that code on slow ATM machines. There is a cost of 1-2 seconds delay. – U.Kaya Jul 22 '12 at 23:05

2 Answers2

0

Use the ElementName value in your binding.

<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>

If ElementName doesn't work for you, then try RelativeSource.

Rhyous
  • 6,510
  • 2
  • 44
  • 50
0
IsIconButtonVisible="{Binding Path=DataContext.ViewModelProperty,RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Window}}}" 

I hope this will help.

yo chauhan
  • 12,079
  • 4
  • 39
  • 58