Bạn không thể kế thừa mã XAML nó tự Tuy nhiên việc tạo ra một lớp trừu tượng của codebehind, sẽ cho phép bạn chỉnh sửa trong mã phía sau, từ một đối tượng lớp được thừa kế
XAML Mã số:.. {Window1.XAML }
<Window
x:Class="WPFSamples.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="auto" Width="256" Title="WPF Sameples">
<Grid>
<Button x:Name="Button1" VerticalAlignment="Center" HorizontalAlignment="Center" Content="Click Me"/>
</Grid>
</Window>
CodeBehind: {} Window1.xaml.cs
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 WPFSamples
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public abstract partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
}
}
nguồn gốc class: {} DisabledButtonWindow.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WPFSamples
{
public sealed class DisabledButtonWindow : Window1
{
public DisabledButtonWindow()
{
Button1.IsEnabled = false;
}
}
}
mặc dù bạn không thể kế thừa từ nguồn wpf nó tự, bạn có thể sử dụng điều khiển "Window1" làm mẫu cho tất cả các điều khiển có nguồn gốc khác.
cho cách giải quyết WPF với kế thừa Visual xem: http://svetoslavsavov.blogspot.gr/2009/09/user-control-inheritance-in-wpf.html hoặc để xác định rõ ràng GUI trong tổ tiên xem http: // support.microsoft.com/kb/957231 –