小编Mrg*_*Gek的帖子

使用MVVM时放置事件的位置?

我应该将所有事件放在视图代码中,还是有更合适的方法,比如在ViewModel中放置命令?例如,我想双击datagrid行打开Tab,我应该在哪里处理这个事件?

wpf event-handling mvvm

8
推荐指数
2
解决办法
7049
查看次数

如何在StackPanel或ListView中叠加项目?

我正在制作一个纸牌游戏,我想在玩家的手中显示半张相互覆盖的牌.如何使用ListView或StackPanel执行此操作?这是一个如何显示玩家手牌的示例.

球员手

<Grid Background="Green" >
        <Image x:Name="One" Width="100" Height="100" Margin="10,10,250,210"/>
        <Image x:Name="Two" Width="100" Height="100" Margin="10,10,210,210"/>
</Grid>
Run Code Online (Sandbox Code Playgroud)

UPDATE

我为ListView的ItemContainerStyle设置了边距并且它有效,但我有另一个问题.ListView项目的宽度不适合图像,并且有一些间距.我该如何删除它.请参阅XAML代码下方的图像.

<ListView Grid.Row="0" Grid.Column="0">
        <ListView.ItemsPanel>
            <ItemsPanelTemplate>
                <StackPanel Orientation="Horizontal" />
            </ItemsPanelTemplate>
        </ListView.ItemsPanel>
        <ListView.ItemContainerStyle>
            <Style TargetType="ListViewItem">
                <Setter Property="Margin" Value="0, 0, -80, 0"></Setter>
                <Setter Property="Height" Value="100"></Setter>
                <Setter Property="Width" Value="100"></Setter>
            </Style>
        </ListView.ItemContainerStyle>
        <Image x:Name="One" MaxWidth="100" Height="100" />
        <Image x:Name="Two" MaxWidth="100" Height="100" />
    </ListView>
Run Code Online (Sandbox Code Playgroud)

玩家的手

c# xaml listview uwp

8
推荐指数
1
解决办法
2338
查看次数

如何删除/更改 MouseOver 上 MenuItem/ContextMenu 的突出显示颜色?

如何删除/更改 MouseOver 上 MenuItem/ContextMenu 的突出显示颜色?我尝试编辑 ContextMenu 模板并为 MouseOver 上的 MenuItem 设置样式,但默认的 HiglightedColor 仍然存在于 MouseOver 上。

<Style TargetType="{x:Type ContextMenu}">
                    <Setter Property="SnapsToDevicePixels"
              Value="True" />
                    <Setter Property="OverridesDefaultStyle"
              Value="True" />
                    <Setter Property="Grid.IsSharedSizeScope"
              Value="true" />
                    <Setter Property="HasDropShadow"
              Value="True" />
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="{x:Type ContextMenu}">
                                <Border x:Name="Border"
                    Background="Black"
                    BorderThickness="0">
                                    <Border.BorderBrush>
                                        <SolidColorBrush Color="Black" />
                                    </Border.BorderBrush>
                                    <StackPanel IsItemsHost="True"
                          KeyboardNavigation.DirectionalNavigation="Cycle" />
                                </Border>
                                <ControlTemplate.Triggers>
                                    <Trigger Property="HasDropShadow"
                       Value="true">
                                        <Setter TargetName="Border"
                        Property="Padding"
                        Value="0,0,0,0" />
                                        <Setter TargetName="Border"
                        Property="CornerRadius"
                        Value="0" />
                                    </Trigger>
                                    <Trigger Property="IsMouseOver"  Value="True">
                                        <Setter Property="BorderBrush" Value="Transparent"/>
                                        <Setter Property="Background"  Value="Transparent"/>
                                    </Trigger>
                                </ControlTemplate.Triggers> …
Run Code Online (Sandbox Code Playgroud)

c# wpf xaml contextmenu menuitem

0
推荐指数
1
解决办法
3407
查看次数

标签 统计

c# ×2

wpf ×2

xaml ×2

contextmenu ×1

event-handling ×1

listview ×1

menuitem ×1

mvvm ×1

uwp ×1