我对wpf有一些疑问。 有一个我的课Wpf名称“interactiveGrid”在当前上下文中不存在
using System;
using System.Collections.Generic;
using System.Windows.Controls;
namespace RatesScenarios.Controls
{
class InteractiveGrid : Grid, IDisposable
{
//...
}
}
当我把它添加到XAML:
<Window x:Class="RatesScenarios.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:RatesScenarios.Controls"
Title="RatesScenarios" MinHeight="400" Width="700" Background="SteelBlue" SizeToContent="Manual">
及以下
<Grid Background="White">
<Border BorderBrush="#CCCCCC" BorderThickness="1" Margin="7,10,7,10" VerticalAlignment="Top" HorizontalAlignment="Center">
<controls:InteractiveGrid Name="interactiveGrid" ShowGridLines="True" VerticalAlignment="Top" HorizontalAlignment="Center">
</controls:InteractiveGrid>
</Border>
</Grid>
当构建项目节选错误:名称 “interactiveGrid” 不存在目前的情况下
namespace RatesScenarios
{
public partial class MainWindow : Window
{
private void Refresh()
{
interactiveGrid.Children.Clear();
}
}
}
为什么发生?
您是否尝试将公共添加到控件的定义中?公共类InteractiveGrid – rauland 2014-10-06 06:50:54
是的,“公共类InteractiveGrid”也不起作用。定义“类InteractiveGrid”必须工作,因为它在单个程序集中声明 – Andre 2014-10-06 06:54:38
您是否尝试过x:Name =“interactiveGrid”而不是Name =“interactiveGrid”? – rauland 2014-10-06 07:10:09