【发布时间】:2020-06-02 07:56:30
【问题描述】:
我有这种情况:一个 ListView 和每个 Cell 都是一个框架。当显示列表时,当我单击框架时,所有框架的背景颜色都是白色的,我希望颜色在 blie 中改变。我改变颜色但不清爽。这是我的代码: 在xml页面中
<pages:PopupPage.Resources>
<local1:ChangeFrameBackgroudColor x:Key="ChangeFrameBackgroudColor" />
</ResourceDictionary>-->
</pages:PopupPage.Resources>
<ListView x:Name="IzberiFirmaListView" HasUnevenRows="True" ItemsSource="{Binding KorisnikFirmi}" SelectedItem="{Binding IzbranaFirmaId } " Header="{Binding}" ItemTapped="IzberiFirmaListView_ItemTapped">
<ListView.ItemTemplate >
<DataTemplate>
<local:ExtendedViewCell SelectedBackgroundColor="#2188ff" >
<StackLayout Padding="20, 10" >
<Frame x:Name="frameLabel" BorderColor="#2188ff" BackgroundColor="{Binding IsActive, Converter={StaticResource ChangeFrameBackgroudColor}}">
<Label FontAttributes="Bold" FontSize="18" TextColor="Black" Text="{Binding Naziv}" ></Label>
</Frame>
</StackLayout>
</local:ExtendedViewCell>
</DataTemplate>
</ListView.ItemTemplate>
<ListView.HeaderTemplate>
<DataTemplate>
<ContentView BackgroundColor="#006BE6" >
<Label Margin="10" HorizontalOptions="CenterAndExpand" Text="ОДБЕРЕТЕ ФИРМА" TextColor="White" FontSize="20" FontAttributes="Bold"/>
</ContentView>
</DataTemplate>
</ListView.HeaderTemplate>
</ListView>
在 xaml.cs 页面中:
private void IzberiFirmaListView_ItemTapped(object sender, ItemTappedEventArgs e)
{
var vm = BindingContext as OdberiFirmaPopupViewModel;
var firm = e.Item as SysDashFirma;
vm.ChangeColorOnItemSelected(firm);
}
在视图模型中
public List<SysDashFirma> KorisnikFirmi
{
get { return korisnikFirmi; }
set
{
if (korisnikFirmi != value)
{
korisnikFirmi = value;
SetProperty(ref korisnikFirmi, value);
OnPropertyChanged("KorisnikFirmi");
}
}
}
public void ChangeColorOnItemSelected(SysDashFirma firm)
{
if (_oldFirmSelected == firm)
{
//firm.BackColor = "#2188ff";
firm.IsActive = true;
UpdateSelectedFirmItemColor(firm);
}
else
{
if(_oldFirmSelected != null)
{
//_oldFirmSelected.BackColor = "#f5f5f5";
_oldFirmSelected.IsActive = false;
UpdateSelectedFirmItemColor(_oldFirmSelected);
}
// firm.BackColor = "#2188ff";
firm.IsActive = true;
UpdateSelectedFirmItemColor(firm);
}
_oldFirmSelected = firm;
}
private void UpdateSelectedFirmItemColor(SysDashFirma firm)
{
var index = KorisnikFirmi.IndexOf(firm);
KorisnikFirmi.Remove(firm);
KorisnikFirmi.Insert(index,firm);
}
在列表中进行了更改,标志已更改,可能无法刷新出价上下文以使转换器从头开始读取所有内容。
【问题讨论】:
-
我有几个疑问,您是否将 OnPropertyChanged 用于 IsActive 属性?更改 IsActive 属性时转换器代码是否触发?(使用断点检查)
-
我在 SysDashFirma 对象中有 IsActive
-
我在该列表中有 Inotify
-
当我更改选定公司的值时,转换器不会触发
-
您在列表中有 INotify,但您更改了
SysDashFirma对象的 IsActive 属性。IsActive更改不会通知您的 UI。请尝试将 OnPropertyChanged 添加到IsActive属性。我错过了什么吗?
标签: xaml xamarin xamarin.forms xamarin.android xamarin.ios