Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
280
Making ListBoxItem draggable or not draggable depending on conditions.
posted

I have created a custom ListBoxTemplate for ListBox Item which displays the Image and other information (Example: Employee).  I need a scenario in which the listbox item should be draggable /not draggable based on some conditions(Ex: If FirstName is null then not draggable). How can I achieve this? 

The xaml-code snippet that i am using right now is as follows:

-------------------------------------

<DataTemplate>

<StackPanel Orientation="Horizontal" >
<StackPanel.Background>
<Binding Path="Background" RelativeSource="{RelativeSource Mode=FindAncestor, AncestorType={x:Type ListBoxItem}}"/>
</StackPanel.Background>
<Border x:Name="ImageBorder" BorderThickness="1" BorderBrush="Gray" Margin="5,5,0,5">
<Image Source="{Binding ImagePath}" Width="64" Height="64" />
</Border>
<StackPanel Orientation="Vertical" Margin="5,10,5,0">
<TextBlock Text="{Binding JobTitle}" FontWeight="Bold" />
<TextBlock Text="{Binding FirstName}" VerticalAlignment="Center" />
<TextBlock Text="{Binding LastName}" />
</StackPanel>
<!--allow an item to be dragged by setting the DragSource object’s IsDraggable property to True.-->
<ig:DragDropManager.DragSource >
<ig:DragSource x:Name="ListItemBoxDragSource" IsDraggable="True" DragChannels="ChannelA" DragStart="DragSource_DragStart" Drop="DragSource_Drop" >
</ig:DragSource>
</ig:DragDropManager.DragSource>
<ig:DragDropManager.DropTarget>
<ig:DropTarget IsDropTarget="True" DropChannels="ChannelA">
</ig:DropTarget>
</ig:DragDropManager.DropTarget>
</StackPanel>
<DataTemplate.Triggers>
<DataTrigger Binding="{Binding Path=FirstName}" Value="{x:Null}">
<Setter TargetName="ImageBorder" Property="BorderBrush" Value="Red" />
<Setter TargetName="ListItemBoxDragSource" Property="IsDraggable" Value="False"/>
</DataTrigger>
</DataTemplate.Triggers>
</DataTemplate>

---------------------------------------------

Since, the present xaml gives error of "TargetName" not defined because it is not a valid visual component. How can I achieve  set/reset of draggable property of DropSource. 

Help..

Thank you in advance...

Parents Reply Children
No Data