Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WPF Itemcontrol数据模板_C#_Wpf_Mvvm_Datatemplate_Itemsource - Fatal编程技术网

C# WPF Itemcontrol数据模板

C# WPF Itemcontrol数据模板,c#,wpf,mvvm,datatemplate,itemsource,C#,Wpf,Mvvm,Datatemplate,Itemsource,我是WPF的新手,我不能解决这个问题,希望你们能帮我解决这个问题。问题是DesignerItemTemplate在项目控件中时不起作用,我尝试将其直接用于一个项目,我可以将其拖动。如果代码看起来很混乱,请原谅。提前谢谢 <UserControl.Resources> <ControlTemplate x:Key="MoveThumbTemplate" TargetType="{x:Type s:MoveThumb}"> <Rectangle

我是WPF的新手,我不能解决这个问题,希望你们能帮我解决这个问题。问题是
DesignerItemTemplate
在项目控件中时不起作用,我尝试将其直接用于一个项目,我可以将其拖动。如果代码看起来很混乱,请原谅。提前谢谢

<UserControl.Resources>
    <ControlTemplate x:Key="MoveThumbTemplate" TargetType="{x:Type s:MoveThumb}">
        <Rectangle Fill="Transparent" />
    </ControlTemplate>

    <!-- ResizeDecorator Template -->
    <ControlTemplate x:Key="ResizeDecoratorTemplate" TargetType="{x:Type Control}">
        <Grid>
            <StackPanel VerticalAlignment="Top" HorizontalAlignment="Left" Height="15" Width="130" Margin="0,-15,-81,0" IsHitTestVisible="False">
                <TextBox Text="R101" BorderBrush="Transparent" IsHitTestVisible="False"  Background="Transparent" Height="17" FontSize="7" Foreground="#FF6DF90C"   VerticalContentAlignment="Stretch" MinHeight="1"  HorizontalAlignment="Stretch" CharacterCasing="Upper"   />
            </StackPanel>

            <s:ResizeThumb Height="1" Cursor="SizeNS"  BorderBrush="#FF160DCD" BorderThickness="1"
                           VerticalAlignment="Top" HorizontalAlignment="Stretch"/>
            <s:ResizeThumb Width="1" Cursor="SizeWE"   BorderBrush="#FF160DCD" BorderThickness="1"
                           VerticalAlignment="Stretch" HorizontalAlignment="Left"/>
            <s:ResizeThumb Width="1" Cursor="SizeWE"    BorderBrush="#FF160DCD" BorderThickness="1"
                           VerticalAlignment="Stretch" HorizontalAlignment="Right"/>
            <s:ResizeThumb Height="1" Cursor="SizeNS"    BorderBrush="#FF160DCD" BorderThickness="1"
                           VerticalAlignment="Bottom" HorizontalAlignment="Stretch"/>
            <s:ResizeThumb Width="2" Height="2" Cursor="SizeNWSE"   BorderBrush="#FF81F110" BorderThickness="1"
                           VerticalAlignment="Top" HorizontalAlignment="Left"/>
            <s:ResizeThumb Width="2" Height="2" Cursor="SizeNESW"   BorderBrush="#FF81F110" BorderThickness="1"
                           VerticalAlignment="Top" HorizontalAlignment="Right"/>
            <s:ResizeThumb Width="2" Height="2" Cursor="SizeNESW"   BorderBrush="#FF81F110" BorderThickness="1"
                           VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
            <s:ResizeThumb Width="2" Height="2" Cursor="SizeNWSE"  BorderBrush="#FF81F110" BorderThickness="1"
                           VerticalAlignment="Bottom" HorizontalAlignment="Right"/>
        </Grid>
    </ControlTemplate>

    <!-- Designer Item Template-->
    <ControlTemplate x:Key="DesignerItemTemplate" TargetType="{x:Type ContentControl}">
        <Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">
            <s:MoveThumb Template="{StaticResource MoveThumbTemplate}" Cursor="SizeAll"/>
            <Control Template="{StaticResource ResizeDecoratorTemplate}"/>
            <ContentPresenter Content="{TemplateBinding Content}"/>
        </Grid>
    </ControlTemplate>
</UserControl.Resources>

<panZoom:PanAndZoomViewer  x:Name="panZoomViewer" Margin="2,2,2,45" ClipToBounds="True">
    <!--<Canvas>-->
    <Canvas x:Name="cnvImage" Background="Transparent">
        <Image x:Name="imgCurrent" VerticalAlignment="Center" HorizontalAlignment="Center" />
        <ItemsControl ItemsSource="{Binding InspectionItemList,Mode=TwoWay }">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    <ContentControl Canvas.Top="{Binding Y,Mode=TwoWay}" Canvas.Left="{Binding X,Mode=TwoWay }" 
                                    Width="{Binding Width,Mode=TwoWay}" MinWidth="1" 
                                    Height="{Binding Height,Mode=TwoWay}"   MinHeight="1"  
                                    Template="{Binding Mode=OneWay, Source={StaticResource DesignerItemTemplate}}" />
                </DataTemplate>
            </ItemsControl.ItemTemplate>
        </ItemsControl>
    </Canvas>
    <!--</Canvas>-->
</panZoom:PanAndZoomViewer>

代替Template=“{Binding Mode=OneWay,Source={StaticResource DesignerItemTemplate}”/>尝试以下操作:

Template="{Binding Mode=OneWay, Source={StaticResource DesignerItemTemplate}}" /> Template="{StaticResource DesignerItemTemplate}" /> Template=“{StaticResource DesignerItemTemplate}”/>
如果这没有帮助,请您提供一个简单一点的例子来说明问题,并描述您想要实现的目标。我不清楚你想得到什么。

我发现了问题!继承到可观察对象的是InspectionItemList集合对象。当我移除对象中的obeservable时,它可以完美地工作。感谢Clemens和Stackoverflow,这个网站真的帮了我很大的忙。

应该是这样的:嗨,Clemence,我遵循了结构,所有的数据模板现在都不会显示。