I've managed to reduce this to a simple test case. An exception is thrown during the parsing of this XAML using XamlReader.Parse()
:
<DockPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DockPanel.Resources>
<Style TargetType="TextBox">
<Style.Triggers>
<Trigger Property="IsReadOnly" Value="True">
<Setter Property="Background" Value="#FFEEEEEE" />
</Trigger>
</Style.Triggers>
</Style>
</DockPanel.Resources>
<TextBox IsReadOnly="True" />
</DockPanel>
The exception message is:
Cannot set unknown member 'System.Windows.Controls.TextBox.IsReadOnly'. Line number '13' and line position '11'.
If I don't set IsReadOnly
on the TextBox
, it parses fine. It also parses fine if I remove the style trigger.
Can anyone shed some light on this? I'm rather new to WPF.
UPDATE:
Here's the unit test I'm using to reproduce this (it's failing on my PC):
[TestMethod]
public void TestIsReadOnlyOnTextBox()
{
// Arrange
var xaml =
@"<DockPanel xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">
<DockPanel.Resources>
<Style TargetType=""TextBox"">
<Style.Triggers>
<Trigger Property=""IsReadOnly"" Value=""True"">
<Setter Property=""Background"" Value=""#FFEEEEEE"" />
</Trigger>
</Style.Triggers>
</Style>
</DockPanel.Resources>
<TextBox IsReadOnly=""True"" />
</DockPanel>
";
// Act
try {
var root = XamlReader.Parse(xaml);
}
catch (XamlParseException ex) {
Assert.Fail(ex.Message);
}
// If we get here, test passes
}
UPDATE 2:
I was originally referencing just PresentationFramework v4.0.30319. Adding references to PresentationCore, System.Xaml, and WindowsBase has no effect.
.NET version of project is 4 (full, not client profile).
UPDATE 3:
Arg, this works fine in ExpressionBlend 3.0.1927.0 and XamlPadX 4. As reported by AresAvatar, it seems to only fail when parsed with XamlReader.Parse()
or XamlReader.Load()
!
XamlReader.Load(stream)
(which causes the same exception). – BellayTargetType="TextBox"
toTargetType="{x:Type TextBox}"
, just for my sanity. I had a weird problem that occurred from not using the longhand notation. – PurgationXamlReader.Parse()
has an overload that accepts aParserContext
. I'm saying everything you need is probably set in that context. I don't know how to set it myself, I've been messing with this for a while but couldn't figure out how this should be set. You should look into this. – FarrisIsReadOnly="True"
though, which leads me to think it's not something in the context. – Bellay