WPF錯誤:cannot set name attribute value '{control}'
April 13, 2014 at 3:45 PM
—
Admin

來源:Open Clip Art根據Public Domain條款下使用
我發現WPF的User Control,不容許它的子元件有Name屬性的。例如:
<advgenControls:CollapsibleControl> <TreeView
x:Name="treeView" Style="{StaticResource MainLeftPanel}" /></advgenControls:CollapsibleControl>
這樣就會這個錯誤出現:
Cannot set Name attribute value 'treeView' on element 'TreeView'. 'TreeView' is under the scope of element 'CollapsibleControl', which already had a name registered when it was defined in another scope. Line 93 Position 5. (MC3093) - D:\Projects\AdvGenContact\AdvGenContact\AdvGenContact.WPF\MainWindow.xaml:93,5
那使我不能在主程式,直接呼叫那元件。
我花了一些時間找尋解決方案,都無法克服的。我認為我是錯用了UserControl.UserControl只是一些可重用的內容。例如我有一款一式一樣的Status Bar必需放置在每一個Window上的,那就應該用User Control.如果好像以上的例子,我只想造一個像Outlook般的可接合的Panel,應該找一個現有的WPF Control來伸延(Override)的。以我的例子來說,我應該找HeaderItemsControl
按:我將會把可接合的Panel元件在AdvGen Contact Manager上發佈的。
76807f9a-0e0d-4eff-be32-7edfbe5f1a50|0|.0
Posted in: C#
Tags: