2
我有一個問題是我離開不高興。我想拖放一個項目在列表視圖中,當我將一個樣式應用於我的項目時,我無法做到這一點。只有當我沒有應用樣式(MyButtonStyle)/或樣式中沒有此圖像時,我才能做到並且工作完美。當我有風格(MyButtonStyle)時,不調用ItemDragStarting事件。拖放UWP vs按鈕樣式
另一種情況:我點擊了關聯的事件,並且當我應用這個樣式時崩潰。我不明白問題是什麼,有人可以幫助我嗎?
謝謝:
代碼的MainPage:
<ListView x:Name="MyListView" ItemsSource="{x:Bind _ObservableCollection}" Style="{StaticResource MyListViewStyle}" SelectionMode="None" CanDragItems="True" DragItemsStarting="MyListView_OnDragItemsStarting">
<ListView.ItemTemplate>
<DataTemplate>
<Button Tapped="Item_Tapped" Style="{StaticResource MyButtonStyle}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
XAML代碼風格:
<Style x:Key="MyButtonStyle" TargetType="Button">
<Setter Property="Background" Value="{StaticResource MyColor1}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Border x:Name="ButtonContent" Background="{TemplateBinding Background}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="PointerOver">
<Storyboard>
<ColorAnimation Storyboard.TargetName="ButtonContent" To="{StaticResource MyColor2}"
Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
Duration="00:00:00.1"/>
</Storyboard>
</VisualState>
<VisualState x:Name="Pressed">
<Storyboard>
<PointerDownThemeAnimation TargetName="ButtonContent"/>
<ColorAnimation Storyboard.TargetName="ButtonContent" To="{StaticResource MyColor3}"
Storyboard.TargetProperty="(Border.Background).(SolidColorBrush.Color)"
Duration="00:00:00.1"/>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Image Width="200" Height="200">
<Image.Source>
<BitmapImage UriSource="{Binding MyImage, Mode=OneTime}" />
</Image.Source>
</Image>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Hi @Filip Skakun,謝謝你的回覆。 在ItemContainerStyle中應用這種風格非常困難,或者我不明白我在做什麼。 – fipcurren88