I have created a custom control library called
Base_Dialog
, and in that library I created a control,
BaseDlg
, like this:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Base_Dialog
{
public class BaseDlg : Window
{
static BaseDlg()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(BaseDlg), new FrameworkPropertyMetadata(typeof(BaseDlg)));
}
}
}
And in "Generic.xaml":
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:Base_Dialog"
xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation">
<Style TargetType="{x:Type local:BaseDlg}" x:Name="local1">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:BaseDlg}">
<Grid Name="gidBaseDlg" >
<Grid.Background>
<ImageBrush ImageSource="/Base%20Dialog;component/Image/Window.png"/>
</Grid.Background>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ContentPresenter x:Name="windowContent"
Content="{TemplateBinding Property=ContentControl.Content}"
Margin="4" Grid.Row="0" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
And I wrote the following code in the "AssemblyInfo.cs" file:
[assembly: XmlnsDefinition("http://schemas.sheva.com/winfx/2006/xaml/presentation", "Base_Dialog")]
then open wpfapplication name((wpf))and add references Project ((Base_Dialog))
The XAML for the control:
<local:BaseDlg x:Class="wpf.Box"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="http://schemas.sheva.com/winfx/2006/xaml/presentation"
Title="Box" Height="300" Width="300">
<Grid>
<Button Content="enas" Height="30" Width="30" HorizontalAlignment="Left" VerticalAlignment="Top"/>
</Grid>
</local:BaseDlg>
I want change the background for
BaseDlg
at runtime then have and every window inheriting from this
BaseDlg
use the same background.
How can I change the background for my custom control at runtme?