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

1

2

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

Facile answered 7/1, 2015 at 0:16 Comment(0)
O
2

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;
    }
}

enter image description here

Object answered 7/1, 2015 at 5:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.