كيف يمكنني تطبيق تأثير على الحدود ولكن ليس على محتوياتها في WPF؟

StackOverflow https://stackoverflow.com/questions/807420

  •  03-07-2019
  •  | 
  •  

سؤال

لدي تطبيق WPF يحتوي على شبكة بيانات تابعة لجهة خارجية مع حدود حولها.لقد استخدمت DropShadowEffect لوضع ظل خلف الحدود، ولكن يبدو أن هذا يؤثر على الأداء إلى حد ما (ليس بقدر ما BitmapEffect, ، ولكن لا يزال ملحوظًا) ويجعل عرض الخط غامضًا.هل هناك طريقة لتطبيق التأثير بطريقة أو بأخرى على الحدود، ولكن ليس محتوياتها؟

حاولت ضبط التأثير على المحتويات على {x:Null}, ، لكن ذلك لم يساعد.

إليك نموذج تطبيق توصلت إليه.فهو يضع ظلاً خلف الحدود، ولكنه يضع أيضًا ظلاً خلف كل سطر من النص.أريد الظل خلف الحدود، لكن ليس النص.

<Window x:Class="WpfEffectTest.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid>
        <Border BorderBrush="Black" BorderThickness="10" CornerRadius="5" Margin="25">
            <Border.Effect>
                <DropShadowEffect BlurRadius="10" ShadowDepth="5" />
            </Border.Effect>
            <StackPanel>
                <TextBlock>This is some text</TextBlock>
                <TextBlock>This is some text</TextBlock>
                <TextBlock>This is some text</TextBlock>
                <TextBlock>This is some text</TextBlock>
                <TextBlock>This is some text</TextBlock>
                <TextBlock>This is some text</TextBlock>
            </StackPanel>
        </Border>

    </Grid>
</Window>
هل كانت مفيدة؟

المحلول

وكان الارتباط من gcores الجواب، الذي هو وضع الحدود ومحتواه معا في نفس الشبكة بحيث يعلو محتوى الحدود.

<Window x:Class="WpfEffectTest.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300">
    <Grid>
        <Border BorderBrush="Black" BorderThickness="10" CornerRadius="5" Margin="25">
            <Border.Effect>
                <DropShadowEffect BlurRadius="10" ShadowDepth="5" />
            </Border.Effect>
        </Border>
        <StackPanel Margin="35">
            <TextBlock>This is some text</TextBlock>
            <TextBlock>This is some text</TextBlock>
            <TextBlock>This is some text</TextBlock>
            <TextBlock>This is some text</TextBlock>
            <TextBlock>This is some text</TextBlock>
            <TextBlock>This is some text</TextBlock>
        </StackPanel>
    </Grid>
</Window>

نصائح أخرى

أحد الحلول البسيطة (الاختراق؟) هو القيام بذلك

<StackPanel Background="White">

يجب أن يحل هذا النص الذي به مشكلة الظل المنسدل (لكن لست متأكدًا من مشكلة الأداء).تكمن المشكلة في أن WPF يطبق التأثيرات على العنصر المحدد وجميع العناصر التابعة له في الشجرة المرئية.وهذا الرابط يوضح ذلك بشكل أفضل:مشكلة في أداء DropShadowEffect

وحاول كتلة التالي (أو ما شابه) لجميع TextBlocks:

<TextBlock>
    <TextBlock.Effect>
        <DropShadowEffect BlurRadius="30" ShadowDepth="5" Color="White"/>
    </TextBlock.Effect>
</TextBlock>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top