C# 更改ListView Xamarin.Forms中的TextColor

C# 更改ListView Xamarin.Forms中的TextColor,c#,xaml,listview,xamarin.forms,C#,Xaml,Listview,Xamarin.forms,另外,我在XAML中有ListView和TextCell,但我想更改textColor 在我的代码中 我正在为我的应用程序制作深色模式,我有下一个问题: 单元格-文本单元格 Cell.TextColor=Color.White显示错误:当前上下文中不存在单元格 如何将其绑定到我的上下文或更改文本颜色。请告诉我做那件事的方法 UPD: 创建单元格: 我用XAML做的 <StackLayout Margin="20,35,20,20" x:Name="Main_View2">

另外,我在XAML中有ListView和TextCell,但我想更改textColor 在我的代码中

我正在为我的应用程序制作深色模式,我有下一个问题: 单元格-文本单元格

Cell.TextColor=Color.White显示错误:当前上下文中不存在单元格

如何将其绑定到我的上下文或更改文本颜色。请告诉我做那件事的方法

UPD:

创建单元格:

我用XAML做的

     <StackLayout Margin="20,35,20,20" x:Name="Main_View2">
            <ListView x:Name="Main_Menu" ItemsSource="{Binding Planets}" ItemSelected="Handle_ItemSelected" ItemTapped="Handle_ItemTapped">
            <ListView.ItemTemplate>
            <DataTemplate >
             <TextCell Text="{Binding Name}" x:Name="labelTable" TextColor="#FF851B">

            </TextCell>
            </DataTemplate>
             </ListView.ItemTemplate>
              </ListView>

      </StackLayout >

Way-1颜色如下:

<ListView ItemsSource="{Binding Planets}" CachingStrategy="RecycleElement">
    <ListView.ItemTemplate>
        <DataTemplate>
            <TextCell Text="{Binding Name}" TextColor="White"/>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

Way-2:在模型中定义一个属性(行星)并在其中提供颜色,然后按如下方式绑定:

<ListView ItemsSource="{Binding Planets}" CachingStrategy="RecycleElement">
    <ListView.ItemTemplate>
        <DataTemplate>
            <TextCell Text="{Binding Name}" TextColor="{Binding MyTextColor}"/>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

Way-3:在ViewModel中为TextColor定义一个属性,然后像下面那样绑定它

Color myTextColor = Color.White;
public Color MyTextColor
{
    get { return myTextColor; }
    set { SetProperty(ref myTextColor, value); }
}


<ListView x:Name="Main_Menu" ItemsSource="{Binding Planets}" CachingStrategy="RecycleElement">
    <ListView.ItemTemplate>
        <DataTemplate>
            <TextCell Text="{Binding Name}" TextColor="{Binding Source={x:Reference Main_Menu}, Path=BindingContext.MyTextColor}"/>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>
Color myTextColor=Color.White;
公共颜色MyTextColor
{
获取{return myTextColor;}
set{SetProperty(ref myTextColor,value);}
}

希望对您有所帮助。

Way-1请按以下方式选择颜色:

<ListView ItemsSource="{Binding Planets}" CachingStrategy="RecycleElement">
    <ListView.ItemTemplate>
        <DataTemplate>
            <TextCell Text="{Binding Name}" TextColor="White"/>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

Way-2:在模型中定义一个属性(行星)并在其中提供颜色,然后按如下方式绑定:

<ListView ItemsSource="{Binding Planets}" CachingStrategy="RecycleElement">
    <ListView.ItemTemplate>
        <DataTemplate>
            <TextCell Text="{Binding Name}" TextColor="{Binding MyTextColor}"/>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

Way-3:在ViewModel中为TextColor定义一个属性,然后像下面那样绑定它

Color myTextColor = Color.White;
public Color MyTextColor
{
    get { return myTextColor; }
    set { SetProperty(ref myTextColor, value); }
}


<ListView x:Name="Main_Menu" ItemsSource="{Binding Planets}" CachingStrategy="RecycleElement">
    <ListView.ItemTemplate>
        <DataTemplate>
            <TextCell Text="{Binding Name}" TextColor="{Binding Source={x:Reference Main_Menu}, Path=BindingContext.MyTextColor}"/>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>
Color myTextColor=Color.White;
公共颜色MyTextColor
{
获取{return myTextColor;}
set{SetProperty(ref myTextColor,value);}
}

希望有帮助。

我可以利用以下资源做到这一点: `

App.Current.Resources[“textColor”]=Color.Black`

在XAML中:

TextColor="{DynamicResource Key=textColor}"

我可以利用以下资源做到这一点: `

App.Current.Resources[“textColor”]=Color.Black`

在XAML中:

TextColor="{DynamicResource Key=textColor}"

显示创建
单元格的代码。除此之外,您应该在xaml.I升级的描述中使用带有绑定的ViewModel。查看并显示行星属性的视图模型和项目模型显示创建
单元格的代码。除此之外,您应该在xaml.I升级的描述中使用带有绑定的ViewModel。Look还显示Planets propertySetProperty的视图模型和项目模型(参考myTextColor,值);显示一个错误。这是我如何实现propertychange的。您需要根据实现propertychange的方式替换该行。检查您定义的其他属性,并根据需要进行更改;显示一个错误。这是我如何实现propertychange的。您需要根据实现propertychange的方式替换该行。检查您定义的其他属性,并根据需要进行更改。