小编Ioa*_*cur的帖子

WebActivatorEx与OwinStartup

例如,在WebAPI应用程序中,有什么区别

[assembly: OwinStartup(typeof(MyClass), "MyMethod")]
Run Code Online (Sandbox Code Playgroud)

[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(MyClass), "MyMethod")]
Run Code Online (Sandbox Code Playgroud)

asp.net web owin

19
推荐指数
2
解决办法
7483
查看次数

在DataTemplates中绑定时,"无法找到管理FrameworkElement ..."警告

当绑定到DataTemplate内的 SolidColorBrush属性时,我在Visual Studio输出窗口中收到此警告:

System.Windows.Data错误:2:找不到目标元素的管理FrameworkElement或FrameworkContentElement.BindingExpression:路径= MyColor; 的DataItem = NULL; target元素是'SolidColorBrush'(HashCode = 22943289); 目标属性是'颜色'(类型'颜色')

如果我直接绑定在DataTemplate外部的矩形元素上,那么一切都很好.

任何人都可以从下面的示例代码中解释为什么这两个明显相似的用法存在差异:

我的看法:

<UserControl.Resources>

    <vm:TestViewModel x:Key="_myTestVM"/>

    <DataTemplate x:Key="testVMDataTemplate">
        <Grid>
            <Rectangle Height="30" Width="200" Margin="5">
                <Rectangle.Fill>
                    <SolidColorBrush Color="{Binding Path=MyColor}" />
                </Rectangle.Fill>
            </Rectangle>
        </Grid>
    </DataTemplate>
</UserControl.Resources>

<Grid>
    <StackPanel DataContext="{StaticResource _myTestVM}">
        <!-- Binding *outside* the DataTemplate = works fine -->
        <Rectangle Height="30" Width="200" Margin="5">
            <Rectangle.Fill>
                <SolidColorBrush Color="{Binding Path=MyColor}"/>
            </Rectangle.Fill>
        </Rectangle>

        <!-- Binding *inside* the DataTemplate = output warning -->    
        <ContentControl Content="{Binding}" ContentTemplate="{StaticResource testVMDataTemplate}"/>
    </StackPanel>
</Grid>
Run Code Online (Sandbox Code Playgroud)

我的ViewModel(TestViewModel):

public class TestViewModel …
Run Code Online (Sandbox Code Playgroud)

wpf warnings datatemplate

13
推荐指数
1
解决办法
9916
查看次数

标签 统计

asp.net ×1

datatemplate ×1

owin ×1

warnings ×1

web ×1

wpf ×1