0

I’ve inherited a UserControl to add some functionality, and it works great. MyUserControl is in a different project, and I simply use it in main project, the problem is that anytime I open the xaml it will not render until I make a change and build. After that the layout refreshes all the time, but if I close the user control and reopen it does not display anything unless I build. Here is the 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>

Here is the 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));
}

There is nothing special about this code and I don’t know why it does not refresh until I buid. These two files are in different projects, and the xaml will work as soon as I do anychange like add space and build. Any ideas?

Kind Regards

adminSoftDK
  • 2,012
  • 1
  • 21
  • 41
  • I am not sure whether this is related to your problem, but you could perform the `SetValue` call in the constructor only when the designer is not active like shown here: http://stackoverflow.com/a/834332/4424024 If you do stuff in the parameterless contructor, you always have the possibility to break the designer, because the some objects used in the constructor do not exist at design time. – Martin Sep 21 '15 at 13:19
  • @Martin Thank you for your answer, the problem was actually that style = FindResource() as the reasource was yet at another location, I had to build everytime I opend a view. So I went a dirrent route, instead there is no style, and the stuff that was in the style is in that usercontrol, and it is fine now. I am going to delete this post as it won't give any value to anyone I think. – adminSoftDK Sep 21 '15 at 14:54

1 Answers1

1

After you make changes to a UserControl in a different project, the designer figures out that the UserControl it's displaying is out of date. Therefore you will need to build/rebuild the solution so the designer can catch up and display the latest changes on the designer.

When you build or run the solution, things should be okay.

Mike Eason
  • 9,525
  • 2
  • 38
  • 63
  • Thank you for your answer, the problem was actually that style = FindResource() as the reasource was yet at another location, I had to build everytime I opend a view. So I went a dirrent route, instead there is no style, and the stuff that was in the style is in that usercontrol, and it is fine now. I am going to delete this post as it won't give any value to anyone I think. – adminSoftDK Sep 21 '15 at 14:54