c# - 在ListView中选择时更改UserControl的样式

标签 c# xaml mvvm uwp

我有一个UserControl作为具有依赖项属性的ListView的DataTemplate。

第1页

<!-- ListView -->
<ListView  ItemSource="{x:bind ViewModel.Profils}" SelectionMode="Single" SelectedItem="x:bind ViewModel.SelectedProfil, Mode="TwoWay", Converter={}}">

    <ListView.ItemTemplate>
        <DataTemplate x:DataType="vm:AbstractProfilVM">
            <!-- Master -->
            <widget:CelProfilMaster CelProfilMasterName={x:Bind Name} CelProfilMasterAge={x:Bind Age} ... />
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

<!-- Details -->
<widget:CelDetail CelProfilDetailsName="{x:bind ViewModel.SelectedProfil.Name}..."/>

它工作正常,但是当在列表 View 中选择我的UserControl时,如何更改其背景?

最佳答案

您应该重写ListView样式并更改Selected VisualState

关于c# - 在ListView中选择时更改UserControl的样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38584258/

相关文章:

c# - 像那样使用 EventHandler 有什么意义?

c# - ASP.NET 用户控件中的 Javascript 函数

c# - 4个接口(interface)的接口(interface)?

wpf - MVVM 中具有依赖属性的用户控件

c# - DataTemplate 多个数据触发相同的元素和属性

c# - 如何在 ASP.NET MVC 项目中生成用于 knockout 的客户端 View 模型?

wpf - ResourceDictionary 样式错误 : "type must derive from FrameworkElement or FrameworkContentElement

wpf - ComboBox和 Entity Framework ,如何获取ID? (WPF-MVVM)

c# - 尝试在我的WPF应用程序(ColumnSeries)中构建一个简单的实时图表

c# - 在文本框中发生任何更改时立即更改按钮的启用状态?