2014-04-15 6 views
0

저는 WPF를 처음 사용하고 WPF 사용자 지정 컨트롤을 작성했습니다. 다음은 내 코드입니다.WPF 사용자 지정 컨트롤에 단추 추가

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 textbtn 
{ 
    public class CustomControl1 : Control 
    { 
     static CustomControl1() 
     { 
      DefaultStyleKeyProperty.OverrideMetadata(typeof(CustomControl1), new FrameworkPropertyMetadata(typeof(CustomControl1))); 
     }   

     private void button1_Click(object sender, RoutedEventArgs e) 
     { 
      //if (test.Width > 50) 
      // test.Width = 0; 
      //else   
      // test.Width = 100; 
     } 
    } 
} 

내 XAML 코드 :

<ResourceDictionary 
    x:Class="textbtn.CustomControl1" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:local="clr-namespace:textbtn"> 
    <Style TargetType="{x:Type local:CustomControl1}"> 
     <Setter Property="Template"> 
      <Setter.Value> 
       <ControlTemplate TargetType="{x:Type local:CustomControl1}"> 
        <Border Background="{TemplateBinding Background}" 
          BorderBrush="{TemplateBinding BorderBrush}" 
          BorderThickness="{TemplateBinding BorderThickness}"> 
         <Grid> 
          <Button Content="CButton" Height="23" HorizontalAlignment="Center" Name="button1" VerticalAlignment="Center" Width="75" Click="button1_Click"/> 
          <TextBlock Text="This is a Test" Foreground="Aqua" Background="AntiqueWhite" /> 
         </Grid> 
        </Border>      
       </ControlTemplate> 
      </Setter.Value> 
     </Setter> 
    </Style> 
</ResourceDictionary> 

나는 다음과 같은 오류를 얻고있다. 저를 고치는데 도와주세요. 미리 감사드립니다.

오류 1 'textbtn.CustomControl1'유형의 선언에 부분 수정자가 누락되었습니다. 이 유형의 다른 부분 선언은

+0

음 오류 메시지가 매우 명시 적이다. 이 클래스를 두 곳에서 정의했으며 다른 선언에서는 부분적입니다. 둘 중 하나만 유지하십시오. – Dmitry

+0

한 곳에서만 정의했습니다. – user2998181

답변

0

이와

public class CustomControl1 : Control 

를 교체 존재합니다

public partial class CustomControl1 : Control 
+0

도움이되지 않았습니다. 다음과 같은 오류가 발생했습니다. 'textbtn.CustomControl1'의 오류 부분 선언은 '당신이 된 UserControls 시작하면 어떻게 무엇을 컨트롤하지 않는 ResourceDictionary에 – user2998181

+0

다른 기본 클래스를 지정하지 않아야합니다. – csharpwinphonexaml

+0
관련 문제