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

4k views Asked by At

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...

2

There are 2 answers

1
Dustin Davis On BEST ANSWER

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>

0
Jon Skeet On

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.