canvas1改另外个名字,可能你有控件命名这个了

解决方案 »

  1.   

    <UserControl x:Class="WpfControlLibrary1.UserControl1"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Height="40" Width="100" FlowDirection="LeftToRight" Canvas.Left="0" Canvas.Top="0" Background="White">
        <Canvas Height="105" Name="canvas1" Width="111" HorizontalAlignment="Left" VerticalAlignment="Top">
            <Image Canvas.Left="25" Canvas.Top="40" Height="50" Name="image1" Stretch="Fill" Width="50" Margin="0" />
            <TextBox Canvas.Left="0" Canvas.Top="0" Height="40" Name="textBox1" Width="100" IsReadOnly="True" Cursor="Hand" IsEnabled="True" Focusable="False">hihi</TextBox>
        </Canvas>
    </UserControl>
      

  2.   

    Name="canvas1" 
    Name="image1"
    Name="textBox1" 
    这个自定义控件中含有上面三个小控件,这些小控件都不能有名字,不然执行下列语句时候报错
    Object obj = XamlReader.Load(ms);
    报错:无法在元素“Canvas”上设置名称属性值“canvas1”。“Canvas”在元素“UserControl1”的范围内,在另一范围定义它时已注册名称。 行“3”位置“13”。