Localized UserControl at Design Time - winforms

I build an UserControl which is localizable. The UserControl's Localizable Property is set to true and I have already a localized label on this control. I add this control to a Form. This Form's Localizable Property is also set to true.
At runtime this label is correct localized. But I like to have also a preview of this localized UserControl at Design Time when I switch the Form's Language Property.
Is it possible to have a preview of this localized UserControl at Design Time? If yes, how?

Related

Show a control in designer when the Visiblity's Fallbackvalue is set to 'Hidden'

in several Views we have container components - for example Grid or ScrollViewer- that are bound to a property on their own ViewModel or ViewModelItem.
In some cases the View (parent) containing these components can be shown without the ViewModel/ViewModelItem of the components being initialized. To avoid showing a user empty datagrids we are using FallBackValue=Hidden to make sure the container is only shown when it's ViewModel/ViewModelItem is initialized/loaded.
A hypothetical example would be a Window containing a DataGrid and a more detailed view to the right. The detailed view would be its own UserControl with its own ViewModel and the DataGrid would have its own ViewModel as well. When opening said Window the ViewModel of the DataGrid would be loaded immediately - but since no row has been selected the ViewModel that belongs to the detailed View would not be intialized, which means that the Visibility Binding of the detail View would fail and the binding's FallbackValue would be used to hide the detail View.
The issue with this approach is that the Visual Studio WPF/XAML designer will not show the content of the affected containers since they are hidden due to their FallbackValue.
Question: Is there a way to get the designer to show specific controls/components that have the FallBackValue of a Visibility binding set to Hidden? Clicking into the XAML code that is inside these hidden containers does not show them.
Edit 1
I found this answer. Setting d:IsHidden="false" does not help. Regardless of if it's set before or after the Visibility property.
When it comes to the designer you would have to set the Design Data Context.
To do that you would typically do the following in your xaml file:
<Control, Page or Window
xmlns:vm="clr-namespace:VM.ViewModel"
d:DataContext="{d:DesignInstance {x:Type vm:YourViewModelNameHere}, IsDesignTimeCreatable=True}"
.../>
However, sometimes like in your case, more flexibility is needed for the complex ViewModel. For this I would use Blend and it's functionality, what that is it will generate dummy data for you and set the data context of the Control for you.
For more information refer to this MSDN article.

Custom Control Appearance

I created my own user controls that inherit from the standard .net controls (for example MyTextBox : TextBox). MyTextBox has within it some custom logic, and also sets some style properties (eg colour). I build the project that contains these controls, and they get added to my toolbox. I then drag them onto the windows form designer. The problem is that when I drag them, the windows form designer automatically includes the style definition for the control that i dragged. For example
this.myTextBox1.BackColor = System.Drawing.Color.Gray;
Now, if later on during development I decide to change the colour for all instance of MyTextBox in the solution from Gray to White, I cannot simply go to the MyTextBox control code, change it there and rebuild. The change will not be applied to existing text boxes, since this property will be overridden in the forms designer! What is the best approach to handle such cases?
you can control the designer code generation with an attribute ... http://msdn.microsoft.com/en-us/library/system.componentmodel.designerserializationvisibilityattribute.aspx

Can I make a custom control similar to a ContentControl editable in Blend?

I'm trying to make a custom control in Silverlight have the same functionality as a ContentControl, notably being editable in Blend.
The custom control has a property "AdditionalContent" which holds the Content that should be displayed. It is bound to and displayed with a ContentPresenter in the Xaml for the control's UI. Unfortunately, my custom control inherits from a 3rd party control, so inheriting from ContentControl is not an option.
I looked at the Silverlight Toolkit code, at HeaderedContentControl, and used it as guidance to get my "AdditionalContent" property working. The only problem is that it is not friendly to Blend. I'm getting some very basic editability in Blend, but not the smooth integration that Blend has for types of ContentControl or HeaderedContentControl.
Is there any kind of Attribute or something else I can add so Blend knows how to handle this situation? Or is it the case that Blend is hard coded for ContentControl and HeaderedContentControl types?
Add a [ContentPropertyAttribute] to the control specifying the name of the content element.

Templates in extended Silverlight controls

i am looking to extend a third party control, it is a ComboBox (so it isn't the standard Silverlight one, but that shouldn't matter for this question). To do this, i add a new template control to my controls project, then i change the new control to inherit from ComboBox instead of Control. A style has been created for me in the generic.xaml file, so i delete the default border stuff that was inserted, and then add a property setter for the PopupTemplate.
My problem is that when doing it this way, the combobox doesn't (visibly) render in the silverlight application anymore. However, in the constructor of my extension if i comment out the line
this.DefaultStyleKey = typeof(MyComboBox);
and put the PopupTemplate xaml bit in the main silverlight page, it renders correctly. I want the popup template to be declared within the control library, but does this mean that i also have to define the regular Template property? Am i wrong in thinking that anything i don't explicitly specify should just be inherited from the base control?
A control can only have one default style. You need to copy the entire default style of the base control into the Generic.Xaml for you new MyComboBox then adjust it accordingly.

Silverlight databinding a textBlock in another user control

I have a small usercontrol that basically increments or decrements a value by one. The user control has two buttons(one to add and the other to subtract) and a textBlock that is used to display the value.
I am going to have multiple instance of this usercontrol in another usercontrol so I can manipulate values of a dataclass that has an INotifyPropertyChanged interface. My question is how can I databind the textBlock of the value changing usercontrol to the usercontrol I instansiated it in?
First, I want to state that Silverlight 2 does not support element to element binding. That feature is added in Silverlight 3 (out in Beta now). Having said that, I don't think you want to bind controls together anyway. It sounds like you're trying to build a NumericUpDown control and you probably have some class in code behind that's actually doing the incrementing and decrementing.
If that's the case, you can simply subscribe to the click handlers and call a method on your model like Increment or Decrement. Your model can expose a property for the current value and that property is what is bound to your text box.
Now if you're actually trying to build a NumericUpDown control, you might want to check out the Silverlight Toolkit. The toolkit already includes this control and it also supports data binding.
Check out the NumericUpDown Control here and download the toolkit here.
Finally, binding from a child control to a parent control really isn't any different. The parent UserControl has a DataContext and all child controls inherit that. Each individual child control can also have its DataContext set. Binding expressions are always relative to the DataContext and the DataContext can be set in code. In your case, probably to a model of some sort.
I hope that helps.

Resources