2014-10-20 25 views
0

您好我想在WPF窗口中實現用戶定義的類?如何在WPF中實現用戶定義的類

奇怪的是,我已經做了這一點,但這次它只是不工作,我無法找到我的錯誤...

這是類:

Namespace Controls 

    Public Class WorkingPopup 
     Inherits Primitives.Popup 

     Public ReadOnly WorkingLabelProperty As DependencyProperty = DependencyProperty.Register("WorkingLabel", GetType(Label), GetType(WorkingPopup)) 
     Public ReadOnly WorkingProgressBarProperty As DependencyProperty = DependencyProperty.Register("WorkingProgressBar", GetType(ProgressBar), GetType(WorkingPopup)) 

     Private Property WorkingLabel As Label 
      Get 
       Return GetValue(WorkingLabelProperty) 
      End Get 
      Set(value As Label) 
       SetValue(WorkingLabelProperty, value) 
      End Set 
     End Property 
     Private Property WorkingProgressBar As ProgressBar 
      Get 
       Return GetValue(WorkingProgressBarProperty) 
      End Get 
      Set(value As ProgressBar) 
       SetValue(WorkingProgressBarProperty, value) 
      End Set 
     End Property 

     Public Sub New() 
      MyBase.New() 

      Placement = Primitives.PlacementMode.Center 
      StaysOpen = True 
      PopupAnimation = Primitives.PopupAnimation.Fade 

      WorkingLabel = New Label With {.Visibility = Windows.Visibility.Visible, .Content = "Working", .ContentStringFormat = "{0} ..."} 
      WorkingProgressBar = New ProgressBar With {.Height = 20, .Width = 200, .Margin = New Thickness(5)} 

      Child = New Border 

      With DirectCast(Child, Border) 
       .BorderBrush = SystemColors.ActiveBorderBrush 
       .Background = SystemColors.ControlLightLightBrush 
       .BorderThickness = New Thickness(1) 

       .Child = New StackPanel 

       With DirectCast(.Child, StackPanel) 
        .Children.Add(WorkingLabel) 
        .Children.Add(WorkingProgressBar) 
       End With 
      End With 
     End Sub 

     'Some more irrelevant code 
    End Class 

End Namespace 

這是一個有點我的XAML的:

<RibbonWindow x:Class="MainWindow" 
       xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
       xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
       xmlns:ctrl="clr-namespace:WpfApplication3.Controls" 
       Title="MainWindow" Height="600" Width="800" WindowStartupLocation="CenterScreen" ResizeMode="CanResizeWithGrip"> 

    <Grid> 
     <Grid.RowDefinitions> 
      <RowDefinition Height="Auto"/> 
      <RowDefinition Height="*"/> 
      <RowDefinition Height="Auto"/> 
     </Grid.RowDefinitions> 

     <Grid.Children> 
      <ctrl:WorkingPopup/> 

     </Grid.Children> 
    </Grid> 
</RibbonWindow> 

也許是因爲它的星期一早上...但我不明白這一點...

感謝

+0

對不起,我忘了告訴我可以編譯這個項目,但設計者不能再創建設計視圖,並在該行''我得到錯誤**名稱「WorkingPopup」在名稱空間「clr-namespace:WpfApplication3.Controls」中不存在** – dukemadcat 2014-10-20 09:49:50

+0

在MainWindow的相同程序集中是WorkingPopup嗎? – rPulvi 2014-10-20 10:15:09

+0

是的,兩者都是WpfApplication3的一部分 – dukemadcat 2014-10-20 10:17:11

回答

0

變化WorkingPopup從控制的命名空間WpfApplication3

+0

爲了將** WorkingPopup *放入** WpfApplication3命名空間**中,我不得不刪除** Namespace **,否則我只得到命名空間'WpfApplication3.WpfApplication3',懷疑這不是您的意圖。之後,錯誤仍然存​​在。 – dukemadcat 2014-10-20 11:50:47

相關問題