日期:2014-05-17  浏览次数:20903 次

wpf custom control 不显示
各位老师好!

  我做了一个wpf的自定义控件(custom control)。
Generic.xaml文件代码如下:
XML code

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:FileSelectorControl">
    <Style TargetType="{x:Type local:FileSelector}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type local:FileSelector}">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                     
                            <ScrollViewer  Name="scrolls" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
                                <ScrollViewer.Content>
                                    <StackPanel Name= "multi_item" Orientation="Vertical" ScrollViewer.VerticalScrollBarVisibility="Auto">
                                        <StackPanel Orientation="Horizontal" Height="30" Margin="0,5,0,0">
                                            <Button Name="add_item" Content="增加" Margin="5,0,0,0" Width="80" ></Button>
                                            <Button Name="del_item" Content="删除" Margin="5,0,0,0" Width="80"  />
                                        </StackPanel>

                                        <StackPanel Name="stack_static" Orientation="Horizontal" Height="30" Margin="0,5,0,0">
                                            <TextBox Name="textBox_FileFullName"  Margin="5,0,5,0" Width="330"></TextBox>
                                            <Label Content="名称"    Margin="5,0,5,0"></Label>
                                            <TextBox Name="displayName" Margin="5,0,5,0" Width="200"></TextBox>
                                            
                                            <Button Name="button_browser"  Content="浏览"/>
                                        </StackPanel>

                                        <StackPanel Name="dynamic_item">


                                        </StackPanel>
                                    </StackPanel>
                                </ScrollViewer.Content>
                            </ScrollViewer>

                        
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>



类的代码如下FileSelector.cs
C# code

using System;
using System.Linq;              //程序用到LINQ 
using System.Windows;           //TemplatePartAttribute
using System.Collections.Generic;
using System.Windows.Controls;  //Control
using System.Windows.Input;     //RoutedUICommand
using Microsoft.Win32;          //对话框OpenFileDialog

namespace FileSelectorControl
{
    [TemplatePart(Name = "textBox_FileFullName", Type = typeof(TextBox))]
    public class FileSelector : Control
    {
        static FileSelector()
        {