我继承了一个UserControl来添加一些功能,它工作得很好。MyUserControl是在一个不同的项目,我只是在主项目中使用它,问题是,任何时候我打开xaml它不会渲染,直到我做出改变和构建。之后,布局一直刷新,但如果我关闭用户控件并重新打开它不显示任何东西,除非我构建。这里是xaml
<cc:FormUserControl x:Class="Module.Options.Views.Accounting.Views.JournalFormView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:cc="clr-namespace:Module.Common.Controls;assembly=Module.Common">
<TextBox Grid.Row="1" Text=”Some Text” />
</cc:FormUserControl>
这是c#
public class FormUserControl : UserControl, IView
{
public FormUserControl()
{
SetValue(ViewModelLocator.AutoWireViewModelProperty, true);
}
public override void EndInit()
{
if (CanRefresh)
{
Resources.MergedDictionaries.Add(
new ResourceDictionary().AddResource("/Resource.Dictionaries;component/Styles/MyControlStyle.xaml"));
Style = FindResource("MyserControlStyle") as Style;
}
base.EndInit();
}
public bool CanRefresh
{
get { return (bool)GetValue(CanRefreshProperty); }
set { SetValue(CanRefreshProperty, value); }
}
public static readonly DependencyProperty CanRefreshProperty =
DependencyProperty.Register("CanRefresh", typeof(bool), typeof(FormUserControl), new PropertyMetadata(false));
}
这段代码没有什么特别的,我不知道为什么直到我构建它才刷新。这两个文件在不同的项目中,只要我做任何更改,如添加空间和构建,xaml就会工作。什么好主意吗?
亲切的问候
在不同的项目中更改UserControl
后,设计师发现它显示的UserControl
过时。因此,您需要构建/重新构建解决方案,以便设计器可以赶上并在设计器上显示最新的更改。
当您构建或运行解决方案时,一切都应该没问题。