Windows Phone 8.1 消息应用中使用的文本控件 [英] Text control used in Windows Phone 8.1 messaging app
问题描述
我需要一个类似于 WP 8.1 消息应用程序使用的文本控件,该控件显示 up &指向左上角"和右下角"的向下箭头.我找不到一个.我确实看到使用类似控件的其他应用程序,例如whapsapp"、line"等.
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.
谢谢,阿玛尔
推荐答案
这不需要自定义控件.您可以创建一个普通的 TextBox 或 TextBlock 并在其下方(或上方)添加一个三角形.使用模板选择器根据正在聊天的人选择左侧或右侧:
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:
XML:
<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>
模板选择器:
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;
}
}
这篇关于Windows Phone 8.1 消息应用中使用的文本控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!