Skip to content

Commit 23189c9

Browse files
committed
UG content updated
1 parent a3ce5f7 commit 23189c9

File tree

3 files changed

+326
-2
lines changed

3 files changed

+326
-2
lines changed

wpf/AI-AssistView/Open-AI.md

Lines changed: 163 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,166 @@ Set the ViewModel as the DataContext for the AI AssistView or the parent window.
208208
{% endhighlight %}
209209
{% endtabs %}
210210

211-
![WPF AI AssistView control open ai](aiassistview_images/wpf_aiassistview_openai.gif)
211+
![WPF AI AssistView control open ai](aiassistview_images/wpf_aiassistview_openai.gif)
212+
213+
## Customize Response using ViewTemplateSelector
214+
215+
{% tabs %}
216+
{% highlight C# %}
217+
218+
public class AIMessage : NotificationObject, ITextMessage
219+
{
220+
221+
private string solution;
222+
223+
/// <summary>
224+
/// Gets or sets the text to be display as the message.
225+
/// </summary>
226+
public string Solution
227+
{
228+
get
229+
{
230+
return this.solution;
231+
}
232+
set
233+
{
234+
this.solution = value;
235+
RaisePropertyChanged(nameof(Solution));
236+
}
237+
}
238+
239+
private Author author;
240+
241+
/// <summary>
242+
/// Gets or sets the author to be display in the message.
243+
/// </summary>
244+
public Author Author
245+
{
246+
get { return author; }
247+
set
248+
{
249+
author = value;
250+
RaisePropertyChanged(nameof(Author));
251+
}
252+
}
253+
254+
private DateTime dateTime;
255+
256+
/// <summary>
257+
/// Gets or sets the date and time details when the message was created.
258+
/// </summary>
259+
public DateTime DateTime
260+
{
261+
get { return dateTime; }
262+
set
263+
{
264+
dateTime = value;
265+
RaisePropertyChanged(nameof(DateTime));
266+
}
267+
}
268+
269+
private string text;
270+
271+
/// <summary>
272+
/// Gets or sets the text to be display as the message.
273+
/// </summary>
274+
public string Text
275+
{
276+
get { return text; }
277+
set { text = value; RaisePropertyChanged(nameof(Text)); }
278+
}
279+
}
280+
281+
public class ViewTemplateSelector : DataTemplateSelector
282+
{
283+
public DataTemplate AITemplate { get; set; }
284+
285+
public override DataTemplate SelectTemplate(object item, DependencyObject container)
286+
{
287+
if (item is AIMessage)
288+
{
289+
return AITemplate;
290+
}
291+
return null;
292+
}
293+
}
294+
295+
{% endhighlight %}
296+
{% endtabs %}
297+
298+
{% tabs %}
299+
{% highlight xaml %}
300+
301+
<Page
302+
x:Class="GettingStarted.MainPage"
303+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
304+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
305+
xmlns:local="using:GettingStarted"
306+
xmlns:mdxam="clr-namespace:MdXaml;assembly=MdXaml"
307+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
308+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
309+
xmlns:syncfusion="using:Syncfusion.UI.Xaml.Chat"
310+
mc:Ignorable="d"
311+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
312+
<Window.Resources>
313+
<local:ViewTemplateSelector x:Key="viewTS">
314+
<local:ViewTemplateSelector.AITemplate>
315+
<DataTemplate>
316+
<Border Background="Transparent">
317+
<StackPanel>
318+
<Image Height="200" Width="500"
319+
Source="statue-liberty.jpg"
320+
HorizontalAlignment="Left"/>
321+
<mdxam:MarkdownScrollViewer
322+
Markdown="{Binding Text}"
323+
Foreground="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"
324+
VerticalScrollBarVisibility="Auto"
325+
IsHitTestVisible="False"
326+
Padding="8">
327+
<mdxam:MarkdownScrollViewer.MarkdownStyle>
328+
<Style TargetType="FlowDocument" BasedOn="{x:Static mdxam:MarkdownStyle.Standard}">
329+
<Setter Property="FontSize" Value="12"/>
330+
<Setter Property="FontFamily" Value="Segoe UI"/>
331+
<Style.Resources>
332+
<Style TargetType="Paragraph" x:Key="H1">
333+
<Setter Property="FontSize" Value="20"/>
334+
<Setter Property="FontWeight" Value="Bold"/>
335+
<Setter Property="Margin" Value="0,0,0,8"/>
336+
</Style>
337+
<Style TargetType="Paragraph" x:Key="H2">
338+
<Setter Property="FontSize" Value="16"/>
339+
<Setter Property="FontWeight" Value="SemiBold"/>
340+
<Setter Property="Margin" Value="0,8,0,4"/>
341+
</Style>
342+
<Style TargetType="Image">
343+
<Setter Property="MaxWidth" Value="400"/>
344+
<Setter Property="HorizontalAlignment" Value="Center"/>
345+
</Style>
346+
</Style.Resources>
347+
</Style>
348+
</mdxam:MarkdownScrollViewer.MarkdownStyle>
349+
</mdxam:MarkdownScrollViewer>
350+
</StackPanel>
351+
</Border>
352+
</DataTemplate>
353+
</local:ViewTemplateSelector.AITemplate>
354+
</local:ViewTemplateSelector>
355+
</Window.Resources>
356+
<Grid>
357+
<Grid.DataContext>
358+
<local:ViewModel/>
359+
</Grid.DataContext>
360+
<syncfusion:SfAIAssistView CurrentUser="{Binding CurrentUser}"
361+
Suggestions="{Binding Suggestion}"
362+
ShowTypingIndicator="True"
363+
TypingIndicator="{Binding TypingIndicator}"
364+
Messages="{Binding Chats}"
365+
ViewTemplateSelector="{StaticResource viewTS}"/>
366+
</Grid>
367+
</Page>
368+
369+
{% endhighlight %}
370+
{% endtabs %}
371+
372+
![WPF AI AssistView control open ai](aiassistview_images/wpf_aiassistview_openai1.png)
373+
51.9 KB
Loading

wpf/AI-AssistView/open-ai.md

Lines changed: 163 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,4 +208,166 @@ Set the ViewModel as the DataContext for the AI AssistView or the parent window.
208208
{% endhighlight %}
209209
{% endtabs %}
210210

211-
![WPF AI AssistView control open ai](aiassistview_images/wpf_aiassistview_openai.gif)
211+
![WPF AI AssistView control open ai](aiassistview_images/wpf_aiassistview_openai.gif)
212+
213+
## Customize Response using ViewTemplateSelector
214+
215+
{% tabs %}
216+
{% highlight C# %}
217+
218+
public class AIMessage : NotificationObject, ITextMessage
219+
{
220+
221+
private string solution;
222+
223+
/// <summary>
224+
/// Gets or sets the text to be display as the message.
225+
/// </summary>
226+
public string Solution
227+
{
228+
get
229+
{
230+
return this.solution;
231+
}
232+
set
233+
{
234+
this.solution = value;
235+
RaisePropertyChanged(nameof(Solution));
236+
}
237+
}
238+
239+
private Author author;
240+
241+
/// <summary>
242+
/// Gets or sets the author to be display in the message.
243+
/// </summary>
244+
public Author Author
245+
{
246+
get { return author; }
247+
set
248+
{
249+
author = value;
250+
RaisePropertyChanged(nameof(Author));
251+
}
252+
}
253+
254+
private DateTime dateTime;
255+
256+
/// <summary>
257+
/// Gets or sets the date and time details when the message was created.
258+
/// </summary>
259+
public DateTime DateTime
260+
{
261+
get { return dateTime; }
262+
set
263+
{
264+
dateTime = value;
265+
RaisePropertyChanged(nameof(DateTime));
266+
}
267+
}
268+
269+
private string text;
270+
271+
/// <summary>
272+
/// Gets or sets the text to be display as the message.
273+
/// </summary>
274+
public string Text
275+
{
276+
get { return text; }
277+
set { text = value; RaisePropertyChanged(nameof(Text)); }
278+
}
279+
}
280+
281+
public class ViewTemplateSelector : DataTemplateSelector
282+
{
283+
public DataTemplate AITemplate { get; set; }
284+
285+
public override DataTemplate SelectTemplate(object item, DependencyObject container)
286+
{
287+
if (item is AIMessage)
288+
{
289+
return AITemplate;
290+
}
291+
return null;
292+
}
293+
}
294+
295+
{% endhighlight %}
296+
{% endtabs %}
297+
298+
{% tabs %}
299+
{% highlight xaml %}
300+
301+
<Page
302+
x:Class="GettingStarted.MainPage"
303+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
304+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
305+
xmlns:local="using:GettingStarted"
306+
xmlns:mdxam="clr-namespace:MdXaml;assembly=MdXaml"
307+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
308+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
309+
xmlns:syncfusion="using:Syncfusion.UI.Xaml.Chat"
310+
mc:Ignorable="d"
311+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
312+
<Window.Resources>
313+
<local:ViewTemplateSelector x:Key="viewTS">
314+
<local:ViewTemplateSelector.AITemplate>
315+
<DataTemplate>
316+
<Border Background="Transparent">
317+
<StackPanel>
318+
<Image Height="200" Width="500"
319+
Source="statue-liberty.jpg"
320+
HorizontalAlignment="Left"/>
321+
<mdxam:MarkdownScrollViewer
322+
Markdown="{Binding Text}"
323+
Foreground="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"
324+
VerticalScrollBarVisibility="Auto"
325+
IsHitTestVisible="False"
326+
Padding="8">
327+
<mdxam:MarkdownScrollViewer.MarkdownStyle>
328+
<Style TargetType="FlowDocument" BasedOn="{x:Static mdxam:MarkdownStyle.Standard}">
329+
<Setter Property="FontSize" Value="12"/>
330+
<Setter Property="FontFamily" Value="Segoe UI"/>
331+
<Style.Resources>
332+
<Style TargetType="Paragraph" x:Key="H1">
333+
<Setter Property="FontSize" Value="20"/>
334+
<Setter Property="FontWeight" Value="Bold"/>
335+
<Setter Property="Margin" Value="0,0,0,8"/>
336+
</Style>
337+
<Style TargetType="Paragraph" x:Key="H2">
338+
<Setter Property="FontSize" Value="16"/>
339+
<Setter Property="FontWeight" Value="SemiBold"/>
340+
<Setter Property="Margin" Value="0,8,0,4"/>
341+
</Style>
342+
<Style TargetType="Image">
343+
<Setter Property="MaxWidth" Value="400"/>
344+
<Setter Property="HorizontalAlignment" Value="Center"/>
345+
</Style>
346+
</Style.Resources>
347+
</Style>
348+
</mdxam:MarkdownScrollViewer.MarkdownStyle>
349+
</mdxam:MarkdownScrollViewer>
350+
</StackPanel>
351+
</Border>
352+
</DataTemplate>
353+
</local:ViewTemplateSelector.AITemplate>
354+
</local:ViewTemplateSelector>
355+
</Window.Resources>
356+
<Grid>
357+
<Grid.DataContext>
358+
<local:ViewModel/>
359+
</Grid.DataContext>
360+
<syncfusion:SfAIAssistView CurrentUser="{Binding CurrentUser}"
361+
Suggestions="{Binding Suggestion}"
362+
ShowTypingIndicator="True"
363+
TypingIndicator="{Binding TypingIndicator}"
364+
Messages="{Binding Chats}"
365+
ViewTemplateSelector="{StaticResource viewTS}"/>
366+
</Grid>
367+
</Page>
368+
369+
{% endhighlight %}
370+
{% endtabs %}
371+
372+
![WPF AI AssistView control open ai](aiassistview_images/wpf_aiassistview_openai1.png)
373+

0 commit comments

Comments
 (0)