Text control used in Windows Phone 8.1 messaging app [closed]

风流意气都作罢 提交于 2019-12-06 09:36:51

问题


I need a text control similar to the one used by WP 8.1 messaging app that shows the up & down arrows that point to 'top-left' and 'bottom right'. I am not able to find one. I do see other apps like 'whapsapp', 'line' etc using similar controls.

Is there a preexisting / opensource control available with that functionality. Any pointers or links would be very helpful.

Thanks, Amar


回答1:


This doesn't require a custom control. You can create a normal TextBox or TextBlock and add a triangle underneath (or above) it. Use a template selector to choose left or right based on which person is chatting:

Xaml:

<Page.Resources>
    <DataTemplate x:Key="ChatTemplateR">
        <StackPanel Margin="30,2,0,2">
            <Border Background="{Binding Fill}" >
                <TextBlock MinWidth="200" Text="{Binding Text}" TextWrapping="Wrap"  Margin="5"/>
            </Border>
            <Path x:Name="DownRightTri"
                  HorizontalAlignment="Right" 
                  Margin="0,0,10,0" 
                  Fill="{Binding Fill}"
                  Data="M0,0 H10 V10" />

        </StackPanel>
    </DataTemplate>
    <DataTemplate x:Key="ChatTemplateL">
        <StackPanel Margin="0,2,30,2" >
            <Path x:Name="UpLeftTri"
                  HorizontalAlignment="Left" 
                  Margin="10,0,0,0" 
                  Fill="{Binding Fill}"
                  Data="M0,-5 V5 H10 " />        
            <Border Background="{Binding Fill}" >
                <TextBlock MinWidth="200" Text="{Binding Text}" TextWrapping="Wrap" Margin="5"/>
            </Border>


        </StackPanel>
    </DataTemplate>
    <local:ChatTemplateSelector x:Key="ChatSelector" LeftTemplate="{StaticResource ChatTemplateL}" RightTemplate="{StaticResource ChatTemplateR}"/>
</Page.Resources>

<Grid>
    <ListView x:Name="lv" ItemTemplateSelector="{StaticResource ChatSelector}"/>
</Grid>

TemplateSelector:

class ChatTemplateSelector: DataTemplateSelector
{
    public DataTemplate LeftTemplate { get; set; }
    public DataTemplate RightTemplate { get; set; }

    protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
    {
        DataItem di = (DataItem)item;
        DataTemplate dt = di.IsLeft ? this.LeftTemplate : this.RightTemplate;
        return dt;
    }
}



来源:https://stackoverflow.com/questions/27809505/text-control-used-in-windows-phone-8-1-messaging-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!