I have a custom control in WPF. I added two plain CLR property, that look like this:
private int _ChordFrom = 0;
public int ChordFrom
{
get { return _ChordFrom; }
set { _ChordFrom = value; }
}
private int _ChordTo = 0;
public int ChordTo
{
get { return _ChordTo; }
set { _ChordTo = value; }
}
I use plain CLR properties, because I don't want to bind these properties to any other dependency. I just want to set the values inside XAML, when the control is instantiated.
Inside XAML the properties are found by intellisense, but when building the project I get the error:
"The member "ChordFrom" is not recognized or is not accessible." "The member "ChordTo" is not recognized or is not accessible."
The XAML code looks like this:
<TabItem Header="CHORDS I">
<Grid x:Name="_gridChords_1" Background="AliceBlue">
<mg:MidiChordGrid x:Name="gridMidiChordGrid_1" Grid.Row="1" Grid.Column="1" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" ChordFrom="0" ChordTo="7"/>
</Grid>
</TabItem>
There are three things, I wonder about:
Why does Intellisense offers me the the properties inside XAML, if they are not accessible?
If I close all XAML windows, rebuild the project, the errors disappear.
Even if can build the project without any errors, the properties are not set.
ANSWER | ANSWER | ANSWER | ANSWER | ANSWER | ANSWER | ANSWER
Thanks for all the answers, but the solution/error was inside my code. I forgot to update my grid after setting these two CLR properties. Sorry for this.
But here some facts you may want to know:
To me, using plain CLR properties is the best solution at this point, because the values I pass to the control are hardcoded for every instance of the control and they do not change at runtime. Of course I would want to use attached DPs, if the values changed at runtime, which they don't.
Thank for your quick answers, but it in the end it was a my fault.
I am just confirming that this appears to be a visual studio bug as mentioned in the question. I added a couple properties to a control and spent an hour trying to figure out why it would not build. After reading the above post I simply closed the xaml file, clicked build and it built successfully. Using VS 2013 community sp 4.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.