Binding ContentControl Content for dynamic content

Ok I’ve knocked up a simple example to show you how you can dynamically change the content of the ContentControl using a MVVM(Model-View-ViewModel) approach with data binding. I would recommend that you create a new project and load these files to see how it all works. We first need to implement INotifyPropertyChanged interface. This will … Read more

How to set Control Template in code?

Creating template in codebehind is not a good idea, in theory one would do this by defining the ControlTemplate.VisualTree which is a FrameworkElementFactory. ControlTemplate template = new ControlTemplate(typeof(Button)); var image = new FrameworkElementFactory(typeof(Image)); template.VisualTree = image; Assigning properties is very roundabout since you need to use SetValue and SetBinding: image.SetValue(Image.SourceProperty, …); Also, about the (previously) … Read more

Whats the difference between ContentControl.Template and ContentControl.ContentTemplate

Template property defines the appearence of a Control itself and ContentTemplate defines the template of the Content area of a Control. Interesting point from MSDN: If a Control does not have a ControlTemplate, the Control will not appear in your application. This becomes more clear when we take a look at the data types of … Read more

Display a default DataTemplate in a ContentControl when its content is null or empty?

Simple, you have to bind the content property in the style. Styles won’t overwrite a value on a control if there’s a binding present, even if the value evaluates to Null. Try this. <ContentControl> <ContentControl.Style> <Style TargetType=”ContentControl”> <Setter Property=”Content” Value=”{Binding HurfView.EditedPart}” /> <Style.Triggers> <DataTrigger Binding=”{Binding RelativeSource={x:Static RelativeSource.Self}, Path=Content}” Value=”{x:Null}”> <Setter Property=”ContentControl.Template”> <Setter.Value> <ControlTemplate> <Grid HorizontalAlignment=”Stretch” … Read more

What’s the difference between ContentControl and ContentPresenter?

ContentControl is a base class for controls that contain other elements and have a Content-property (for example, Button). ContentPresenter is used inside control templates to display content. ContentControl, when used directly (it’s supposed to be used as a base class), has a control template that uses ContentPresenter to display it’s content. My rules of thumb … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)