나는 상속이 후하고, 일반 C# 클래스를 생성하여 도구 모음 클래스를 향상시킬 수 있습니다 :WPF에서 ToolBar를 상속하고 XAML 파일을 만들려면 어떻게해야합니까?
public class NiceToolBar : ToolBar
{
private ToolBarTray mainToolBarTray;
public NiceToolBar()
{
mainToolBarTray = new ToolBarTray();
mainToolBarTray.IsLocked = true;
this.Background = new SolidColorBrush(Colors.LightGray);
...
그러나 문제는이 같은 코드에 내 모든 컨트롤을 조작하는 저를 강제로 :
ToolBar toolBar = new ToolBar();
toolBar.Background = new SolidColorBrush(Colors.Transparent);
toolBar.Cursor = Cursors.Hand;
StackPanel sp = new StackPanel();
sp.Orientation = Orientation.Horizontal;
TextBlock tb = new TextBlock();
tb.Text = label;
tb.Margin = new Thickness { Top = 3, Left = 3, Bottom = 3, Right = 10 };
Image image = new Image();
image.Source = new BitmapImage(new Uri("Images/computer.png", UriKind.Relative));
sp.Children.Add(image);
sp.Children.Add(tb);
toolBar.Items.Add(sp);
내가 정말로 필요로하는 것은 XAML이 지루한 매개 변수 지정 및 레이아웃을 수행하는 것입니다.
그래서 새로운 사용자 정의 컨트롤을 만들고 다음과 같이 ToolBar를 상속하도록 코드를 변경하십시오. 그리고 내 XAML에 넣을 :<UserControl x:Class="TestUserControl.Helpers.SmartToolBar"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<StackPanel Orientation="Horizontal">
<Image Source="Images/computer.png"/>
<TextBlock x:Name="TheLabel"/>
</StackPanel>
</UserControl>
그러나 실행할 때
Partial declaration of "TestCallConstructor.Helpers.SmartToolBar" may not define different basis classes
내 사용자 정의 컨트롤을 xaml로 하는 방법은 무엇입니까?