Skip to content

Commit 88b2d03

Browse files
authored
Merge pull request #1976 from syncfusion-content/WPF_989045-SfAiAssistView
UG 989053 Customize response rendering with ViewTemplateSelector in SfAIAssistView
2 parents a511d1d + 467092d commit 88b2d03

File tree

4 files changed

+334
-6
lines changed

4 files changed

+334
-6
lines changed

wpf/AI-AssistView/Input-Toolbar.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: post
33
title: Input Toolbar in WPF AI AssistView control | Syncfusion
4-
description: Learn about the input toolbar feature in the AI AssistView control, which enables users to access quick actions to input textbox responses through toolbar items.
4+
description: The input toolbar in AI AssistView offers quick actions via toolbar items to streamline textbox response entry.
55
platform: wpf
66
control: SfAIAssistView
77
documentation: ug
@@ -38,7 +38,7 @@ Use the ItemTemplate property to define the appearance and behavior of each tool
3838
<DataTemplate>
3939
<Button Height="24" Width="30" Padding="3" >
4040
<Viewbox>
41-
<Path Fill="Black" Stretch="UniformToFill"
41+
<Path Fill="{Binding Foreground, RelativeSource={RelativeSource AncestorType={x:Type syncfusion:SfAIAssistView}}}" Stretch="UniformToFill"
4242
Data="M10.2656 3.0293C10.5 3.0293 10.7207 3.07422 10.9277 3.16406C11.1348 3.25391 11.3145 3.37695 11.4668 3.5332C11.623 3.68555 11.7461 3.86523 11.8359 4.07227C11.9258 4.2793 11.9707 4.5 11.9707 4.73438C11.9707 4.96484 11.9277 5.18164 11.8418 5.38477C11.7559 5.58789 11.6309 5.77148 11.4668 5.93555L6.31055 11.1152C6.16211 11.2637 5.98633 11.3633 5.7832 11.4141L3.46875 11.9824C3.45312 11.9863 3.4375 11.9902 3.42188 11.9941C3.41016 11.9941 3.39453 11.9941 3.375 11.9941C3.27344 11.9941 3.18555 11.957 3.11133 11.8828C3.04102 11.8086 3.00586 11.7207 3.00586 11.6191C3.00586 11.5996 3.00586 11.584 3.00586 11.5723C3.00977 11.5566 3.01367 11.541 3.01758 11.5254L3.60938 9.22266C3.63281 9.12891 3.66992 9.03711 3.7207 8.94727C3.77539 8.85352 3.83594 8.77344 3.90234 8.70703L9.06445 3.52734C9.22461 3.36719 9.4082 3.24414 9.61523 3.1582C9.82617 3.07227 10.043 3.0293 10.2656 3.0293ZM10.2656 3.7793C10.1406 3.7793 10.0195 3.80273 9.90234 3.84961C9.78906 3.89648 9.6875 3.96484 9.59766 4.05469L4.43555 9.24023C4.38477 9.29102 4.35156 9.34766 4.33594 9.41016L3.90234 11.1035L5.60742 10.6816C5.67383 10.666 5.73242 10.6328 5.7832 10.582L10.9395 5.4082C11.0293 5.31836 11.0977 5.21484 11.1445 5.09766C11.1914 4.98047 11.2148 4.85938 11.2148 4.73438C11.2148 4.60547 11.1895 4.48242 11.1387 4.36523C11.0918 4.24805 11.0254 4.14648 10.9395 4.06055C10.8535 3.97461 10.752 3.90625 10.6348 3.85547C10.5215 3.80469 10.3984 3.7793 10.2656 3.7793ZM5.58398 5.95898L5.00391 6.53906L4.5 5.25H1.50586L0.726562 7.25977C0.699219 7.33008 0.652344 7.38672 0.585938 7.42969C0.523438 7.47266 0.455078 7.49414 0.380859 7.49414C0.275391 7.49414 0.185547 7.45898 0.111328 7.38867C0.0371094 7.31836 0 7.23047 0 7.125C0 7.10156 0.00195312 7.07812 0.00585938 7.05469C0.00976562 7.02734 0.015625 7.00391 0.0234375 6.98438L2.64844 0.234375C2.67969 0.160156 2.72656 0.101562 2.78906 0.0585938C2.85156 0.015625 2.92188 -0.00585938 3 -0.00585938C3.07812 -0.00585938 3.14844 0.015625 3.21094 0.0585938C3.27344 0.101562 3.32031 0.160156 3.35156 0.234375L5.58398 5.95898ZM3 1.40039L1.79883 4.5H4.21289L3 1.40039Z"/>
4343
</Viewbox>
4444
</Button>

wpf/AI-AssistView/Open-AI.md

Lines changed: 166 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
layout: post
3-
title: TypingIndicator in WPF AI AssistView control | Syncfusion
3+
title: OpenAI in WPF AI AssistView control | Syncfusion
44
description: Learn about how to connect the AI AssistView control with OpenAI and chat gpt conversation experience.
55
platform: wpf
66
control: SfAIAssistView
@@ -208,4 +208,168 @@ 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 AI Response Rendering with ViewTemplateSelector in SfAIAssistView
214+
Use the [ViewTemplateSelector](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Chat.SfAIAssistView.html#Syncfusion_UI_Xaml_Chat_SfAIAssistView_ViewTemplateSelector) property to assign a DataTemplateSelector that controls how messages (including AI responses) are rendered in SfAIAssistView. The selector can return different DataTemplates based on the message type or role (user/assistant/system), enabling rich presentations such as:
215+
- Markdown (via a Markdown viewer like MdXaml)
216+
- FlowDocument-based layouts
217+
- Images and custom visuals
218+
- HTML (via a WebBrowser control or third-party HTML renderer)
219+
220+
This approach lets you tailor the appearance of assistant messages without modifying your data model.
221+
222+
{% tabs %}
223+
{% highlight xaml %}
224+
<Page
225+
x:Class="GettingStarted.MainPage"
226+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
227+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
228+
xmlns:local="using:GettingStarted"
229+
xmlns:mdxam="clr-namespace:MdXaml;assembly=MdXaml"
230+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
231+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
232+
xmlns:syncfusion="using:Syncfusion.UI.Xaml.Chat"
233+
mc:Ignorable="d"
234+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
235+
<Window.Resources>
236+
<local:ViewTemplateSelector x:Key="viewTS">
237+
<local:ViewTemplateSelector.AITemplate>
238+
<DataTemplate>
239+
<Border Background="Transparent">
240+
<StackPanel>
241+
<Image Height="200" Width="500"
242+
Source="statue-liberty.jpg"
243+
HorizontalAlignment="Left"/>
244+
<mdxam:MarkdownScrollViewer
245+
Markdown="{Binding Text}"
246+
Foreground="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"
247+
VerticalScrollBarVisibility="Auto"
248+
IsHitTestVisible="False"
249+
Padding="8">
250+
<mdxam:MarkdownScrollViewer.MarkdownStyle>
251+
<Style TargetType="FlowDocument" BasedOn="{x:Static mdxam:MarkdownStyle.Standard}">
252+
<Setter Property="FontSize" Value="12"/>
253+
<Setter Property="FontFamily" Value="Segoe UI"/>
254+
<Style.Resources>
255+
<Style TargetType="Paragraph" x:Key="H1">
256+
<Setter Property="FontSize" Value="20"/>
257+
<Setter Property="FontWeight" Value="Bold"/>
258+
<Setter Property="Margin" Value="0,0,0,8"/>
259+
</Style>
260+
<Style TargetType="Paragraph" x:Key="H2">
261+
<Setter Property="FontSize" Value="16"/>
262+
<Setter Property="FontWeight" Value="SemiBold"/>
263+
<Setter Property="Margin" Value="0,8,0,4"/>
264+
</Style>
265+
<Style TargetType="Image">
266+
<Setter Property="MaxWidth" Value="400"/>
267+
<Setter Property="HorizontalAlignment" Value="Center"/>
268+
</Style>
269+
</Style.Resources>
270+
</Style>
271+
</mdxam:MarkdownScrollViewer.MarkdownStyle>
272+
</mdxam:MarkdownScrollViewer>
273+
</StackPanel>
274+
</Border>
275+
</DataTemplate>
276+
</local:ViewTemplateSelector.AITemplate>
277+
</local:ViewTemplateSelector>
278+
</Window.Resources>
279+
<Grid>
280+
<Grid.DataContext>
281+
<local:ViewModel/>
282+
</Grid.DataContext>
283+
<syncfusion:SfAIAssistView CurrentUser="{Binding CurrentUser}"
284+
Suggestions="{Binding Suggestion}"
285+
ShowTypingIndicator="True"
286+
TypingIndicator="{Binding TypingIndicator}"
287+
Messages="{Binding Chats}"
288+
ViewTemplateSelector="{StaticResource viewTS}"/>
289+
</Grid>
290+
</Page>
291+
292+
{% endhighlight %}
293+
{% highlight C# %}
294+
295+
public class ViewTemplateSelector : DataTemplateSelector
296+
{
297+
public DataTemplate AITemplate { get; set; }
298+
299+
public override DataTemplate SelectTemplate(object item, DependencyObject container)
300+
{
301+
if (item is AIMessage)
302+
{
303+
return AITemplate;
304+
}
305+
return null;
306+
}
307+
}
308+
309+
public class AIMessage : NotificationObject, ITextMessage
310+
{
311+
312+
private string solution;
313+
314+
/// <summary>
315+
/// Gets or sets the text to be display as the message.
316+
/// </summary>
317+
public string Solution
318+
{
319+
get
320+
{
321+
return this.solution;
322+
}
323+
set
324+
{
325+
this.solution = value;
326+
RaisePropertyChanged(nameof(Solution));
327+
}
328+
}
329+
330+
private Author author;
331+
332+
/// <summary>
333+
/// Gets or sets the author to be display in the message.
334+
/// </summary>
335+
public Author Author
336+
{
337+
get { return author; }
338+
set
339+
{
340+
author = value;
341+
RaisePropertyChanged(nameof(Author));
342+
}
343+
}
344+
345+
private DateTime dateTime;
346+
347+
/// <summary>
348+
/// Gets or sets the date and time details when the message was created.
349+
/// </summary>
350+
public DateTime DateTime
351+
{
352+
get { return dateTime; }
353+
set
354+
{
355+
dateTime = value;
356+
RaisePropertyChanged(nameof(DateTime));
357+
}
358+
}
359+
360+
private string text;
361+
362+
/// <summary>
363+
/// Gets or sets the text to be display as the message.
364+
/// </summary>
365+
public string Text
366+
{
367+
get { return text; }
368+
set { text = value; RaisePropertyChanged(nameof(Text)); }
369+
}
370+
}
371+
372+
{% endhighlight %}
373+
{% endtabs %}
374+
375+
![WPF AI AssistView control ViewTemplateSelector](aiassistview_images/wpf_aiassistview_openai1.png)
51.9 KB
Loading

wpf/AI-AssistView/open-ai.md

Lines changed: 166 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
layout: post
3-
title: TypingIndicator in WPF AI AssistView control | Syncfusion
3+
title: OpenAI in WPF AI AssistView control | Syncfusion
44
description: Learn about how to connect the AI AssistView control with OpenAI and chat gpt conversation experience.
55
platform: wpf
66
control: SfAIAssistView
@@ -208,4 +208,168 @@ 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 AI Response Rendering with ViewTemplateSelector in SfAIAssistView
214+
Use the [ViewTemplateSelector](https://help.syncfusion.com/cr/wpf/Syncfusion.UI.Xaml.Chat.SfAIAssistView.html#Syncfusion_UI_Xaml_Chat_SfAIAssistView_ViewTemplateSelector) property to assign a DataTemplateSelector that controls how messages (including AI responses) are rendered in SfAIAssistView. The selector can return different DataTemplates based on the message type or role (user/assistant/system), enabling rich presentations such as:
215+
- Markdown (via a Markdown viewer like MdXaml)
216+
- FlowDocument-based layouts
217+
- Images and custom visuals
218+
- HTML (via a WebBrowser control or third-party HTML renderer)
219+
220+
This approach lets you tailor the appearance of assistant messages without modifying your data model.
221+
222+
{% tabs %}
223+
{% highlight xaml %}
224+
<Page
225+
x:Class="GettingStarted.MainPage"
226+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
227+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
228+
xmlns:local="using:GettingStarted"
229+
xmlns:mdxam="clr-namespace:MdXaml;assembly=MdXaml"
230+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
231+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
232+
xmlns:syncfusion="using:Syncfusion.UI.Xaml.Chat"
233+
mc:Ignorable="d"
234+
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
235+
<Window.Resources>
236+
<local:ViewTemplateSelector x:Key="viewTS">
237+
<local:ViewTemplateSelector.AITemplate>
238+
<DataTemplate>
239+
<Border Background="Transparent">
240+
<StackPanel>
241+
<Image Height="200" Width="500"
242+
Source="statue-liberty.jpg"
243+
HorizontalAlignment="Left"/>
244+
<mdxam:MarkdownScrollViewer
245+
Markdown="{Binding Text}"
246+
Foreground="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"
247+
VerticalScrollBarVisibility="Auto"
248+
IsHitTestVisible="False"
249+
Padding="8">
250+
<mdxam:MarkdownScrollViewer.MarkdownStyle>
251+
<Style TargetType="FlowDocument" BasedOn="{x:Static mdxam:MarkdownStyle.Standard}">
252+
<Setter Property="FontSize" Value="12"/>
253+
<Setter Property="FontFamily" Value="Segoe UI"/>
254+
<Style.Resources>
255+
<Style TargetType="Paragraph" x:Key="H1">
256+
<Setter Property="FontSize" Value="20"/>
257+
<Setter Property="FontWeight" Value="Bold"/>
258+
<Setter Property="Margin" Value="0,0,0,8"/>
259+
</Style>
260+
<Style TargetType="Paragraph" x:Key="H2">
261+
<Setter Property="FontSize" Value="16"/>
262+
<Setter Property="FontWeight" Value="SemiBold"/>
263+
<Setter Property="Margin" Value="0,8,0,4"/>
264+
</Style>
265+
<Style TargetType="Image">
266+
<Setter Property="MaxWidth" Value="400"/>
267+
<Setter Property="HorizontalAlignment" Value="Center"/>
268+
</Style>
269+
</Style.Resources>
270+
</Style>
271+
</mdxam:MarkdownScrollViewer.MarkdownStyle>
272+
</mdxam:MarkdownScrollViewer>
273+
</StackPanel>
274+
</Border>
275+
</DataTemplate>
276+
</local:ViewTemplateSelector.AITemplate>
277+
</local:ViewTemplateSelector>
278+
</Window.Resources>
279+
<Grid>
280+
<Grid.DataContext>
281+
<local:ViewModel/>
282+
</Grid.DataContext>
283+
<syncfusion:SfAIAssistView CurrentUser="{Binding CurrentUser}"
284+
Suggestions="{Binding Suggestion}"
285+
ShowTypingIndicator="True"
286+
TypingIndicator="{Binding TypingIndicator}"
287+
Messages="{Binding Chats}"
288+
ViewTemplateSelector="{StaticResource viewTS}"/>
289+
</Grid>
290+
</Page>
291+
292+
{% endhighlight %}
293+
{% highlight C# %}
294+
295+
public class ViewTemplateSelector : DataTemplateSelector
296+
{
297+
public DataTemplate AITemplate { get; set; }
298+
299+
public override DataTemplate SelectTemplate(object item, DependencyObject container)
300+
{
301+
if (item is AIMessage)
302+
{
303+
return AITemplate;
304+
}
305+
return null;
306+
}
307+
}
308+
309+
public class AIMessage : NotificationObject, ITextMessage
310+
{
311+
312+
private string solution;
313+
314+
/// <summary>
315+
/// Gets or sets the text to be display as the message.
316+
/// </summary>
317+
public string Solution
318+
{
319+
get
320+
{
321+
return this.solution;
322+
}
323+
set
324+
{
325+
this.solution = value;
326+
RaisePropertyChanged(nameof(Solution));
327+
}
328+
}
329+
330+
private Author author;
331+
332+
/// <summary>
333+
/// Gets or sets the author to be display in the message.
334+
/// </summary>
335+
public Author Author
336+
{
337+
get { return author; }
338+
set
339+
{
340+
author = value;
341+
RaisePropertyChanged(nameof(Author));
342+
}
343+
}
344+
345+
private DateTime dateTime;
346+
347+
/// <summary>
348+
/// Gets or sets the date and time details when the message was created.
349+
/// </summary>
350+
public DateTime DateTime
351+
{
352+
get { return dateTime; }
353+
set
354+
{
355+
dateTime = value;
356+
RaisePropertyChanged(nameof(DateTime));
357+
}
358+
}
359+
360+
private string text;
361+
362+
/// <summary>
363+
/// Gets or sets the text to be display as the message.
364+
/// </summary>
365+
public string Text
366+
{
367+
get { return text; }
368+
set { text = value; RaisePropertyChanged(nameof(Text)); }
369+
}
370+
}
371+
372+
{% endhighlight %}
373+
{% endtabs %}
374+
375+
![WPF AI AssistView control ViewTemplateSelector](aiassistview_images/wpf_aiassistview_openai1.png)

0 commit comments

Comments
 (0)