x:FieldModifier is not valid for the language C#?

老子叫甜甜 提交于 2019-12-10 19:59:20

问题


When I apply x:FieldModifier to my WPF control, eg:

<TextBox x:Name="textBox1" x:FieldModifier="Public"/>

visual studio (tried on 2008 and 2010) gives me the following error:

x:FieldModifier is not valid for the language C#

How can I solve this problem?

Edit: Sorry, I want to make it public...


回答1:


use lower case 'public' not 'Public'

<Window x:Class="WpfApplication1.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="MainWindow" Height="350" Width="525">
<Grid>
    <TextBox Name="TEst" x:FieldModifier="public" Text="nothing" />
</Grid>




回答2:


Are you sure you actually need FieldModifier? What happens if you don't include it?

From the documentation:

x:FieldModifier is not relevant for declaring the general access level of a class or its members. It is relevant only for XAML-processing behavior when a particular XAML object that is part of a XAML production is processed, and becomes an object that is potentially accessible in the object graph of an application. By default, the field reference for such an object is kept private, which prevents control consumers from modifying the object graph directly. Instead, control consumers are expected to modify the object graph by using standard patterns that are enabled by programming models, such as by obtaining the layout root, the child element collections, the dedicated public properties, and so on.



来源:https://stackoverflow.com/questions/5080648/xfieldmodifier-is-not-valid-for-the-language-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!