我正在开发聊天应用程序。聊天页面包含一个itemTemplateSelector,它通过检查bool值,根据发件人将文本与右端/左端对齐。这是代码
public class ChatTemplateSelector : DataTemplateSelector
{
public DataTemplate LeftTemplate { get; set; }
public DataTemplate RightTemplate { get; set; }
protected override DataTemplate SelectTemplateCore(object item, DependencyObject container)
{
BuddyChat2Datum chat = (BuddyChat2Datum)item;
DataTemplate dt = chat.isLeft ? this.LeftTemplate : this.RightTemplate;
return dt;
}
}
ItemTemplateSelecter:
string text, code;
cout << "Enter Text: ";
getline(cin, text);
for (int i = 0; i < 8 ; i++)
code[i] = text[i] + '1';
cout<<code<<endl;
当聊天框正在改变时,itemtemplateselector正在工作。我无法将rightSide chatBox移动到右端。有什么建议吗?
答案 0 :(得分:2)
您的ListView项目可能没有完全拉伸...尝试将其添加到ListView:
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>