gpt4 book ai didi

WPF 点击用户控件

转载 作者:行者123 更新时间:2023-12-03 10:35:16 25 4
gpt4 key购买 nike

我想让容器窗口内的任何网格行都可以点击。
每行都是一个名为“MyBookControl”的用户控件。
单击 userControl 时,我想提出命令“DownloadCommand”。
我正在使用 mvvm 模式。

容器 View :https://onedrive.live.com/redir?resid=3A8F69A0FB413FA4!124&authkey=!ANdfYAk6f0Vf-8s&v=3&ithint=photo%2cpng

图书控制:

<UserControl  x:Name="MyBookControl" />
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>

<Grid.Style>
<Style TargetType="{x:Type Grid}">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="False">
<Setter Property="Opacity" Value="0.6"></Setter>
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Opacity" Value="1"></Setter>
</Trigger>
</Style.Triggers>
</Style>
</Grid.Style>

<Label Grid.Row="0">Title</Label>
<Label Grid.Row="1">Author</Label>
<Label Grid.Row="2">Description</Label>

<TextBlock Grid.Row="0" Grid.Column="1" Text="{Binding Title}"/>
<TextBlock Grid.Row="1" Grid.Column="1" Text="{Binding Author}"/>
<TextBlock Grid.Row="2" Grid.Column="1" Text="{Binding Description}"/>
<Button Grid.Column="2" Grid.RowSpan="3" Command="{Binding DownloadCommand}" Content="Download" />


<Ellipse Grid.Column="3"
Height="20" Width="20"
Stroke="Black"
StrokeThickness="0.5"
HorizontalAlignment="Center"
Grid.Row="1"
/>
<Controls:PieSlice Grid.Column="3" Grid.Row="1" Stroke="Black" Fill="Black"
Height="20" Width="20"
StartAngle="0" EndAngle="{Binding Percent}"
HorizontalAlignment="Center" />
</Grid>

</UserControl>

最佳答案

据我了解,您想构建一个响应式面板来容纳所有收藏成员。您可以尝试使用 listView 控件,并将您的用户控件作为 ListViewItem 的项目模板。那里的房子有选择功能(ListView)。通过这种方式,ListView 可以通过一堆对象绑定(bind)到您的主视图模型,并且每个用户控件都可以绑定(bind)到单个对象。

     <ListView ItemsSource="{Binding ToYourSourceCollection}">
<ListView.ItemTemplate>
<DataTemplate>
<YourUserControl/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>

然后,您可以构建一个解决 ListView 事件的行为,或者只监听 Selected 属性更改。

关于WPF 点击用户控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33126206/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com