walterlv / BlogComments

3 stars 0 forks source link

post/those-people-dont-know-about-wpf #16

Open utterances-bot opened 5 years ago

utterances-bot commented 5 years ago

WPF 很少人知道的科技 - walterlv

WPF 很少人知道的科技

https://blog.walterlv.com/post/those-people-dont-know-about-wpf.html

lifei8142556 commented 5 years ago

你好大神,使用光照效果使控件冻结了怎么办,控件实例化后就无法从容器里移除此控件了

lifei8142556 commented 5 years ago

在使用光照效果和Storyboard动画的控件都无法对其进行修改,好痛苦! 总是提示: 提供的 DependencyObject 不是用于此 Freezable 的上下文。

lifei8142556 commented 5 years ago

我解决了,直接把你的光照效果改成继承自Border的自定义控件,就不会出现Freezable了

walterlv commented 5 years ago

@lifei8142556 表示没太懂是什么情况呀,把什么改成了继承自 Border

lifei8142556 commented 5 years ago

继承MarkupExtension的话我无法对附加了光照效果的控件在容器中进行添加和移除控件操作,因为它冻结了。 所以我改成了RevealBorder : Border 的独立自定义控件, 然后像

这样来使用~

------------------ 原始邮件 ------------------ 发件人: "walterlv"notifications@github.com; 发送时间: 2019年7月6日(星期六) 上午10:22 收件人: "walterlv/BlogComments"BlogComments@noreply.github.com; 抄送: "丨风之殇丶"lifyjz@vip.qq.com;"Mention"mention@noreply.github.com; 主题: Re: [walterlv/BlogComments] post/those-people-dont-know-about-wpf(#16)

@lifei8142556 表示没太懂是什么情况呀,把什么改成了继承自 Border?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

walterlv commented 5 years ago

@lifei8142556 这是一个不错的用法哟!感谢!不过我这篇博客中的这种写法是为了模拟 UWP 的 API。

CodingOctocat commented 2 years ago

请教一下,如何将 2 维 ObservableCollection 绑定到 ListView? 就是我有一个 Srt 类: class Srt: ObservableCollection<Subtitle> class Subtitle: ObservableCollection<SubtitleUnit> 我需要将一个个 SubtitleUnitListView/WrapPanel 展示出来。

codlin commented 9 months ago
<Window
    x:Class="CompositeCollections.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:CompositeCollections"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Title="MainWindow"
    Width="800"
    Height="450"
    mc:Ignorable="d">
    <Window.Resources>
        <local:GreekGods x:Key="greekGods" />
        <XmlDataProvider x:Key="greekHeroes" XPath="GreekHeroes/Hero">
            <x:XData>
                <GreekHeroes xmlns="">
                    <Hero Name="Jason" />
                    <Hero Name="Hercules" />
                    <Hero Name="Bellerophon" />
                    <Hero Name="Theseus" />
                    <Hero Name="Odysseus" />
                    <Hero Name="Perseus" />
                </GreekHeroes>
            </x:XData>
        </XmlDataProvider>
        <DataTemplate DataType="{x:Type local:GreekGod}">
            <TextBlock Foreground="Gold" Text="{Binding Path=Name}" />
        </DataTemplate>
        <DataTemplate DataType="Hero">
            <TextBlock Foreground="Cyan" Text="{Binding XPath=@Name}" />
        </DataTemplate>
    </Window.Resources>
    <StackPanel>
        <TextBlock
            Margin="10"
            HorizontalAlignment="Center"
            FontSize="18"
            FontWeight="Bold">
            Composite Collections Sample
        </TextBlock>
        <ListBox
            Name="myListBox"
            Width="200"
            Height="300"
            Background="White">
            <ListBox.ItemsSource>
                <CompositeCollection>
                    <CollectionContainer Collection="{StaticResource greekGods}" />
                    <CollectionContainer Collection="{Binding Source={StaticResource greekHeroes}}" />
                    <ListBoxItem Background="red">Other ListBox Item 1</ListBoxItem>
                    <ListBoxItem Background="red">Other ListBox Item 2</ListBoxItem>
                </CompositeCollection>
            </ListBox.ItemsSource>
        </ListBox>
    </StackPanel>
</Window>

请问为什么为什么针对XmlDataProvider提供的 greekHeroes 必须写成这样

<CollectionContainer Collection="{Binding Source={StaticResource greekHeroes}}" />

而针对 CLR 对象的 greekGods 只要写成下面这样就可以了?

<CollectionContainer Collection="{StaticResource greekGods}" />

谢谢