小编man*_*rin的帖子

如何在XAML中将全局枚举指定为Tag值?

我读了几个关于这个问题的问题,但答案对我不起作用.我有以下在StlContainer.cs中声明的枚举:

public enum ToothVisualModelType
{
    CoordinateSystemPivot = 0,
    Tooth = 1,
    Crown = 2,
    Gums = 3
}
Run Code Online (Sandbox Code Playgroud)

枚举在StlContainer类定义之外声明,使其成为全局枚举.我想将其值分配给不同XAML控件的Tag属性,所以我尝试这样做:

<xctk:ColorPicker Tag="{x:Static local:ToothVisualModelType.Tooth}" 
                  Name="colorPickerTooth" 
                  Width="110" 
                  Grid.Column="1" 
                  Grid.Row="3" 
                  SelectedColorChanged="colorPickerTooth_SelectedColorChanged" 
                  DisplayColorAndName="True" 
                  Margin="0,0,10,5">
 </xctk:ColorPicker>
Run Code Online (Sandbox Code Playgroud)

但得到了错误:

错误1未知的构建错误,'键不能为空.参数名称:键行234位置43.' D:\ Visual Studio\Projects\Dental Viewer\Dental Viewer 1.2\Dental Viewer\MainWindow.xaml 234 43 Dental Viewer 1.2

我尝试将枚举移动到MainWindow.xaml.cs,我试过了

Tag="{x:Static local:StlContainer+ToothVisualModelType.Tooth}"
Run Code Online (Sandbox Code Playgroud)

和

Tag="{x:Static MyNamespace:ToothVisualModelType.Tooth}"
Run Code Online (Sandbox Code Playgroud)

我试图将它分配给Label控件上的Tag并仍然得到相同的错误.我在这里错过了什么?我可以使用某种Binding来解决这个问题吗?

PS:当我输入值并进入Tag="{x:Static }"自动完成时,只建议使用Member参数来完成它,Tag="{x:Static Member=}"如果这甚至很重要的话.

.net c# wpf enums xaml

9
推荐指数
2
解决办法
3955
查看次数

WPF将Width绑定到Parent.Width*0.3

我想将控件的宽度绑定到父级的宽度,但是达到一定的比例.有没有办法做这样的事情:

<Rectangle  Name="rectangle1" Width="{Binding ActualWidth*0.3, ElementName=thumbnailCanvas, UpdateSourceTrigger=PropertyChanged}" Height="{Binding ActualHeight, ElementName=thumbnailCanvas, UpdateSourceTrigger=PropertyChanged}"/>
Run Code Online (Sandbox Code Playgroud)

data-binding wpf scale

7
推荐指数
2
解决办法
2万
查看次数

如何在ItemsSource =自定义对象集合时选择/展开TreeView节点?

我TreeView打算在两个级别上操作.对于他我有两个HierarchicalDataTemplate和两个自定义类型.在ItemsSource链接到ObservableCollection,一切工作正常.我无法想象如何从代码隐藏中选择或扩展节点.在某处提到了一个非常好的想法,即绑定IsExpanded和IsSelected属性到我的自定义类型中的相应属性.唯一的问题是HierarchicalDataTemplate没有TreeViewItem直接实现,所以如何在以下代码中访问这些属性?

<TreeView Name="treeViewNotes" AllowDrop="True" PreviewMouseLeftButtonDown="treeViewNotes_PreviewMouseLeftButtonDown" PreviewMouseMove="treeViewNotes_PreviewMouseMove" Drop="treeViewNotes_Drop" DragEnter="treeViewNotes_DragEnter">
    <TreeView.Resources>
        <HierarchicalDataTemplate DataType="{x:Type dataclasses:NoteFolder}" ItemsSource="{Binding Notes}">
            <StackPanel Orientation="Horizontal">
                <Image Height="16" Source="{Binding TreeViewIcon}" Tag="{Binding Self}"/>
                <TextBlock Text="{Binding Title}" Tag="{Binding Self}" Margin="3"/>
            </StackPanel>
        </HierarchicalDataTemplate>
        <HierarchicalDataTemplate DataType="{x:Type dataclasses:Note}">
            <StackPanel Orientation="Horizontal">
                <Image Height="16" Source="{Binding TreeViewIcon}" Tag="{Binding Self}"/>
                <TextBlock Text="{Binding Title}" Tag="{Binding Self}" Margin="3"/>
            </StackPanel>
        </HierarchicalDataTemplate>
    </TreeView.Resources>
</TreeView>
Run Code Online (Sandbox Code Playgroud)

我的目标是创建和添加新的时候Note一些NoteFolder,使这个Note选择和Folder扩展.同样需要进一步改进拖放时的UI响应.

c# data-binding wpf treeview hierarchicaldatatemplate

4
推荐指数
1
解决办法
2854
查看次数

标签 统计

wpf ×3

c# ×2

data-binding ×2

.net ×1

enums ×1

hierarchicaldatatemplate ×1

scale ×1

treeview ×1

xaml ×1