0
我在WPF中做了一個自定義按鈕控件,我試圖在WinForms(c#)中實現它。現在,控件運行良好,但我似乎無法訪問元素主機 - 控件未顯示在工具箱中,之後我看到它已凍結,即我無法將其添加到表單中。由於項目構建過程沒有錯誤或警告,我不知道是什麼導致了這個問題。任何幫助將不勝感激,謝謝。在Visual Studio 2010中凍結的WPF控件
編輯:下面是XAML文件的代碼:
<Button x:Class="proba4.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="120" d:DesignWidth="300" IsEnabled="True">
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Image Name="Normal" Source="C:\stuff\off_button.gif"/>
<Image Name="Pressed" Source="C:\stuff\on_button.gif" Visibility="Hidden"/>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="Normal" Property="Visibility" Value="Hidden"/>
<Setter TargetName="Pressed" Property="Visibility" Value="Visible"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
我想過了,但我沒有作文經驗。有小費嗎? – 2012-03-11 22:24:27
沒關係,我做到了;非常感謝你)。 – 2012-03-11 22:29:01
代碼將與您的代碼類似,但在#1行中將Button標籤替換爲UserControl標籤,並在其內容中添加