이미지 버튼에 재사용 가능한 tamplete를 만들려고했는데이 위크가 advice 인 것으로 나타 났지만 제대로 작동하지 못했습니다. 제발 조언을 해 주시겠습니까? 내가 뭘 잘못하고 있니? 나는 WPF를 가진 꽤 초보자 다. 그래서 그것은 정말로 기본적인 무엇인가일지도 모른다. 그러나 나는 그것을 볼 수 없다.WPF : 이름 XYZ가 XAML 네임 스페이스에 없습니다.
내 ImageButton.cs
클래스 :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace ImageBut
{
public class ImageButton : Button
{
static ImageButton()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(ImageButton),
new FrameworkPropertyMetadata(typeof(ImageButton)));
}
public ImageSource Image
{
get { return (ImageSource)GetValue(ImageProperty); }
set { SetValue(ImageProperty, value); }
}
public static readonly DependencyProperty ImageProperty =
DependencyProperty.Register("Image", typeof(ImageSource), typeof(ImageButton), new PropertyMetadata(default(ImageSource)));
}
}
내 generic.xaml
테마의 하위 폴더.
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="clr-namespace:ImageBut;assembly=ImageBut"
>
<Style x:Key="{x:Type my:ImageButton}" TargetType="{x:Type my:ImageButton}">
<Setter Property="Width" Value="32"></Setter>
<Setter Property="Height" Value="32"></Setter>
<Setter Property="BorderThickness" Value="0"></Setter>
<Setter Property="Margin" Value="4,0,0,0"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Image Source="{TemplateBinding Image}" Stretch="Fill"/>
</Grid>
<ControlTemplate.Triggers>
<!-- Some triggers (IsFocused, IsMouseOver, etc.) -->
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
내 여기
<Window x:Class="ImageBut.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:my="clr-namespace:ImageBut;assembly=ImageBut"
Title="MainWindow" Height="350" Width="525">
<Grid>
<my:ImageButton Image="C:\Users\Martin\Source\Workspaces\Digiterm\ImageBut\ImageBut\1_1.bmp"></my:ImageButton>
</Grid>
</Window>
MainWindow.xaml
내 Project properties하고 여기 Solution Explorer의 Snapchat에서입니다.
예외 내가 점점 오전 :
1>C:\Users\Martin\Source\Workspaces\Digiterm\ImageBut\ImageBut\MainWindow.xaml(7,10): error MC3074: The tag 'ImageButton' does not exist in XML namespace 'clr-namespace:ImageBut;assembly=ImageBut'.
감사합니다!
제안 된 변경 사항을 시도했지만 아무런 문제가 발생하지 않았지만 여전히 동일한 오류가 발생합니다. 내가 원하는 것은 특정 컨트롤을 만드는 것입니다. 따라서 동일한 트리거와 스타일을 모든 단추에 대해 다른 이미지로 정의해야 할 필요는 없습니다. 클래스와 xaml을 수정해야하지만, 우선 적어도이 방법으로 작동하도록하고 싶습니다. – MartinVotruba
그 이유가 확실하지 않습니다. ** ImageButton ** 컨트롤은 ** Window **와 같은 어셈블리에 있습니까? –
나는 어떻게 알아 내는지 모른다. 그것은해야합니다 ... 당신이 괜찮다면, 당신은 내 프로젝트를 검토 할 수 있습니다 - http://goo.gl/J3zmTB 고마워! – MartinVotruba