خرید بک لینک

Vote count: 0

So, I've successfully set up drag-and-drop on a ListBox. I managed to get the UIElements of my choosing from the DataTemplate under the mouse pointer (specifically two Border elements.

However, when I initiate and begin a storyboard, nothing happens.

XAML - DataTemplate and ListBox

<DataTemplate x:Key="TeamHolder">
    <Grid Name="MatchTemplate" Width="390" Height="80" VerticalAlignment="Center">
        <Line Panel.ZIndex="99" Stroke="Red" X1="0" Y1="0" X2="400" Y2="0" Visibility="Hidden" />
        <Border HorizontalAlignment="Left" VerticalAlignment="Top" DataContext="{Binding PlayerA}" BorderThickness="1" Tag="a">
            <Border.Style>
                <Style TargetType="Border">
                    <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="BorderBrush" Value="Red" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="False">
                            <Setter Property="BorderBrush" Value="Black" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </Border.Style>
            <Grid Background="LightBlue" Height="30" Width="300">
                <TextBlock Text="{Binding FullName}" FontSize="16" Margin="5"
                            HorizontalAlignment="Center" VerticalAlignment="Top" Grid.Row="0" />
            </Grid>
        </Border>
        <!--TeamA line-->
        <Line Panel.ZIndex="99" X1="300" Y1="15" X2="350" Y2="15" />
        <!--Coecting line-->
        <Line VerticalAlignment="Top" HorizontalAlignment="Left"
                Margin="350,15,0,15" Stretch="Fill"
                Width="1" X1="0" X2="0" Y1="0" Y2="1" />
        <!--TeamB line-->
        <Line VerticalAlignment="Bottom" Panel.ZIndex="99"
                X1="300" X2="350" Y1="-15" Y2="-15" />
        <Border VerticalAlignment="Bottom" HorizontalAlignment="Left" DataContext="{Binding PlayerB}" BorderThickness="1" Background="LightBlue" Tag="b">
            <Border.Style>
                <Style TargetType="Border">
                    <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="BorderBrush" Value="Red" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="False">
                            <Setter Property="BorderBrush" Value="Black" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </Border.Style>
            <Grid Background="LightBlue" Height="30" Width="300">
                <TextBlock Text="{Binding FullName}" FontSize="16" Margin="5"
                            HorizontalAlignment="Center" VerticalAlignment="Top" Grid.Row="0" />
            </Grid>
        </Border>
        <Line Panel.ZIndex="99" Stroke="Blue" VerticalAlignment="Bottom"
                X1="0" Y1="0" X2="400" Y2="0" Visibility="Hidden" />
    </Grid>
</DataTemplate>

<ListBox x:Name="icTeams" ItemsSource="{Binding CurrentTouament.Teams, Mode=TwoWay}"
                ItemTemplate="{StaticResource TeamHolder}" AllowDrop="True" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                MouseMove="Teams_MouseMove" Drop="Teams_MemberDropped" DragOver="Teams_DragOver"
                DragLeave="Teams_DragLeave" Grid.Row="0" Grid.Column="3">
    <ListBox.ItemsPanel>
        <ItemsPanelTemplate>
            <StackPanel Orientation="Vertical"/>
        </ItemsPanelTemplate>
    </ListBox.ItemsPanel>
</ListBox>

C# - Teams_DragOver

private void Teams_DragOver(object sender, DragEventArgs e)
{
    if (DraggedItem == null) retu;
    // Find the listbox item under the mouse pointer
    var listItem = UIHelpers.TryFindFromPoint<ListBoxItem>((UIElement)sender, e.GetPosition(icTeams));
    // Retu if no listbox item has been found
    if (listItem == null) retu;

    // Using the listbox item, find all the borders (should be 2 with a tag)
    var items = UIHelpers.FindVisualChildren<Border>(listItem).Where(border => border.Tag != null);
    // Retu if there are no borders to animate
    if (items == null || !items.Any()) retu;

    var background = (SolidColorBrush)FindResource("Player.Team.ListItem.Background");

    foreach (var border in items)
    {
        //if (border.Background == null) border.Background = background;
        Storyboard stb = new Storyboard();
        ColorAnimation animation = new ColorAnimation(((SolidColorBrush)FindResource("Player.Team.ListItem.DragOverBackground")).Color, new Duration(TimeSpan.FromSeconds(1)));
        Storyboard.SetTarget(animation, border);
        Storyboard.SetTargetProperty(animation, new PropertyPath("(Border.Background).(SolidColorBrush.Color)"));
        stb.Children.Add(animation);
        stb.Begin(border);
    }
}

After some googling, I believe I have set up my StoryBoard correctly, but nothing happens visually.

What am I missing?

asked 52 secs ago

برچسب: نویسنده: استخدام کار تاريخ: يکشنبه 12 ارديبهشت 1395 ساعت: 17:50

صفحه بندی