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
1810
Drag Drop with XamWebSlider
posted

Hi,

I am using the Drag Drop manager to make my TrackFill of the XamWebSlider as draggable. In the DragTemplate I want to show a list of strings( for which i have property defined). I want to use a Listbox to show the list of strings in the DragBox  while dragging. Is it possible to Databind a listBox in the DragTemplate to a list of strings in the same UserControl ?

I couldnt get the binding to work. Could you point me in the right direction. I did not find any examples with the binding inside the DataTemplate.

I am trying to databind the ListBox in TrackFillStyle to the SelectedCaptions property in the code behind file.

I have attached the sample project

Thanks

Sirish

 

CODE SNIPPET:

 

<Style x:Key="TrackFillStyle" TargetType="igPrimitives:TrackFill">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Grid ShowGridLines="True">
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"></RowDefinition>
                                <RowDefinition Height="Auto"></RowDefinition>
                            </Grid.RowDefinitions>
                            <Rectangle Height="20" Stroke="#FF333333" Grid.Row="1" VerticalAlignment="Bottom" StrokeThickness="0">
                                <Rectangle.Fill>
                                    <LinearGradientBrush EndPoint="0,1.61000001430511" StartPoint="0,0">
                                        <GradientStop Color="#FF47690B" Offset="0.048"/>
                                        <GradientStop Color="#FF78A22F" Offset="0.011"/>
                                        <GradientStop Color="#FFA1D24A" Offset="1"/>
                                    </LinearGradientBrush>
                                </Rectangle.Fill>
                            </Rectangle>
                            <Rectangle Fill="LightBlue" Opacity="0.2" Grid.Row="0" VerticalAlignment="Stretch"
                                       Height="{Binding TrackFillHeight}">
                                <ddm:DragDropManager.DragSource>
                                    <ddm:DragSource IsDraggable="True" Drop="SearchResults_Drop" DragStart="DragSource_DragStart">
                                        <ddm:DragSource.DragTemplate>
                                            <DataTemplate>
                                                <TextBlock Text="some member caption here" Margin="0,0,0,10"></TextBlock>
                                               <!-- <ListBox Width="200" Height="200" Visibility="Visible" x:Name="dragListbox" ItemsSource="{Binding}" >
                                                    <ListBox.ItemTemplate>
                                                        <DataTemplate>
                                                            <TextBlock Text="{Binding}"></TextBlock>
                                                        </DataTemplate>
                                                    </ListBox.ItemTemplate>
                                                </ListBox> -->

                                            </DataTemplate>
                                        </ddm:DragSource.DragTemplate>
                                    </ddm:DragSource>
                                </ddm:DragDropManager.DragSource>
                            </Rectangle>
                            <Rectangle Stroke="#FFFFFFFF" Opacity="0.3" Margin="1"/>
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

 

TimeSelector.zip
Parents
No Data
Reply
  • 8831
    posted

    Hi,

    Maybe you know that until drag-drop operation is in progress there exists an internally created instance of DragObject class and this instance is used as data source for your bindings set in data template used by DragSource.DragTemplate. The DragObject exposes two read-only properties – DragImage and Data.

    1.       DragObject.DragImage keeps the snapshot of dragged element. You can change it when DragStart even is fired.

    2.       DragObject.Data keeps the data object that is relevant to drag-drop operation that is in progress. You can set it using both DragDropStartEventArgs.Data property or set binding for DragSource.DataObject property.

     

    You can set this in your event handler for DragStart event:

     

            private void DragSource_DragStart(object sender, DragDropStartEventArgs e)

            {

                ObservableCollection<string> items = new ObservableCollection<string>();

                items.Add("Item1");

                items.Add("Item2");

                items.Add("Item3");

                items.Add("Item4");

     

                e.Data = items;

            }

     

    And use this data template to visualize the data:

     

            <ddm:DragSource.DragTemplate>

                <DataTemplate>

                    <StackPanel>

                        <ListBox Width="200" Height="200"

                                    Visibility="Visible"

                                    x:Name="dragListbox"

                                    ItemsSource="{Binding Path=Data}"/>

                    </StackPanel>

                </DataTemplate>

            </ddm:DragSource.DragTemplate>

     

    Regards.

     

    PPilev.

Children
No Data