0

ContentPresenter의 content 속성이 String 유형 인 경우 TextBlock이 해당 자식 요소로 자동으로 사용됩니다. 그러나 기본 TextBlock 컨트롤 대신 DynamicTextBlock (CharacterTrimming 용 Silverlight에서 잘 알려진 사용자 컨트롤)이라는 것을 사용하려면 응용 프로그램의 모든 ContentPresenters가 필요합니다.ContentPresenter의 기본 텍스트 블록 변경

어떻게 이런 식으로 달성 할 수 있습니까?

답변

0

하자. 마이크로 소프트는 이미 Silverlight가 치명적이라는 것을 확인했다. 가능하다면 WPF로 건너 뛰어야합니다. 그러나 귀하의 질문에 대답 해 보도록하겠습니다. wpf와 그 속성 값 상속이라는 매우 멋진 것이 있습니다. 내가 어떻게 보여 드릴까요?

public class MyWpfExtension 
{ 
    public static bool GetCharacterEllipsis(DependencyObject obj) 
    { 
     return (bool)obj.GetValue(CharacterEllipsisProperty); 
    } 

    public static void SetCharacterEllipsis(DependencyObject obj, bool value) 
    { 
     obj.SetValue(CharacterEllipsisProperty, value); 
    } 

    // Using a DependencyProperty as the backing store for CharacterEllipsis. This enables animation, styling, binding, etc... 
    public static readonly DependencyProperty CharacterEllipsisProperty = 
     DependencyProperty.RegisterAttached("CharacterEllipsis", typeof(bool), typeof(MyWpfExtension), 
     new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.Inherits, OnCharacterEllipsisChanged)); 

    private static void OnCharacterEllipsisChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 
    { 
     if (d is TextBlock && (bool)e.NewValue) 
     { 
      TextBlock tb = (TextBlock)d; 
      tb.TextTrimming = TextTrimming.CharacterEllipsis; 
     } 
    } 
} 

Btw 이것은 당신이 볼 수있는 WPF입니다. 나는 이것이 당신에게 얼마나 도움이되는지 알지 못하지만 거기에 간다. Silverlight에는이 속성 값 상속도 있다고 가정합니다. 사용에

그리고 지금 :
<StackPanel Background="Blue" local:MyWpfExtension.CharacterEllipsis ="True"> 
    <TextBlock>asdfsadfsadfsadfasdfsadfsadfsadfasdfsadfsadfsadf</TextBlock> 
    <TextBlock>asdfsadfsadfsadfasdfsadfsadfsadfasdfsadfsadfsadf</TextBlock> 
    <TextBlock>asdfsadfsadfsadfasdfsadfsadfsadfasdfsadfsadfsadf</TextBlock> 
    <TextBlock>asdfsadfsadfsadfasdfsadfsadfsadfasdfsadfsadfsadf</TextBlock> 
    <TextBlock>asdfsadfsadfsadfasdfsadfsadfsadfasdfsadfsadfsadf</TextBlock> 
    <TextBlock>asdfsadfsadfsadfasdfsadfsadfsadfasdfsadfsadfsadf</TextBlock> 
    <TextBlock>asdfsadfsadfsadfasdfsadfsadfsadf</TextBlock> 
    <TextBlock>asdfsadfsadfsadfasdfsadfsadfsadf</TextBlock> 
</StackPanel> 

또는 같은

:

<StackPanel Background="Blue" > 
    <ContentPresenter local:MyWpfExtension.CharacterEllipsis="True" Content="fasdfasdfsdffasdfasdfsdffasdfasdfsdffasdfasdfsdf"></ContentPresenter> 
</StackPanel> 

기본적으로 당신이 당신의 연결된 속성의 answere을 설정할 수 있습니다 및 속성이 모든 요소에 상속됩니다. 요소가 TextBlock 인 경우 CharacterElipsis가 설정됩니다.

1

안녕하세요 저는 WPF 프로그래머입니다. 이 솔루션이 Silverlight에서 작동하는지 확인하십시오. 시도해보고 알려주십시오. 아래 코드에서 TextBlock (DataTemplate 내부) 대신 실버 라이트 텍스트 블록 이름을 사용하고 그 결과를 알려주십시오.

<Window x:Class="Editable_ComboBox.MainWindow" 
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
     xmlns:sys="clr-namespace:System;assembly=mscorlib" 
     Title="MainWindow" Height="350" Width="525"> 
    <Window.Resources> 

     <DataTemplate DataType="{x:Type sys:String}" > 
      <TextBlock Text="{Binding}" TextTrimming="CharacterEllipsis" Background="AliceBlue" Foreground="Red" /> 
      <!--In the above line, Remove the TextBlock and use your silvelight dynamic textblock name--> 
     </DataTemplate> 

    </Window.Resources> 
    <Grid> 
     <Button Content="Button" HorizontalAlignment="Left" Margin="204,146,0,0" VerticalAlignment="Top" Width="75"/> 
    </Grid> 
</Window> 
+0

+1 멋진 대답. –

+0

감사합니다. @HeenaPatil – Sivasubramanian