Hide control within a WPF User Control Library

前端 未结 3 823
清歌不尽
清歌不尽 2021-01-07 22:22

I\'ve a project made from the \"WPF User Control Library\" Template in Visual Studio. This project contains one main usercontrol plus additional Windows/Usercontrols.

<
相关标签:
3条回答
  • 2021-01-07 22:55

    Maybe the usage of attributes will solve your problem. There is one attribute "DesignTimeVisible" inside the ComponentModel namespace. If you put such an attribute right above your class implementation and set it to false, the corresponding control should not be visible in the designers toolbox.

    0 讨论(0)
  • 2021-01-07 22:57

    I believe that x:ClassModifier="internal" will make the entire user control internal. This may not be desirable.

    Instead if you add x:FieldModifier="private" to those controls within the user control that you don't wish to be accessible to the UserControl consumer, the generated C# will have those controls as private. Note the use of lower case which is correct for a C# field modifier.

    0 讨论(0)
  • 2021-01-07 23:15

    Make those controls internal. If you have classic UserControls with XAML and codebehind you will need to add x:ClassModifier="internal" to the root element in the XAML:

    <UserControl
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        x:Class="MyNameSpace.MyUserControl"
        x:ClassModifier="internal">
           <!-- bla -->
    </UserControl>
    
    0 讨论(0)
提交回复
热议问题