Skip to content

Commit 17868e8

Browse files
authored
Update open-ai.md
1 parent a621bc2 commit 17868e8

File tree

1 file changed

+87
-86
lines changed

1 file changed

+87
-86
lines changed

wpf/AI-AssistView/open-ai.md

Lines changed: 87 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -211,95 +211,16 @@ Set the ViewModel as the DataContext for the AI AssistView or the parent window.
211211
![WPF AI AssistView control open ai](aiassistview_images/wpf_aiassistview_openai.gif)
212212

213213
## 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)
214219

215-
ViewTemplateSelector allows you to control how AI responses are visually rendered in SfAIAssistView. By assigning a custom DataTemplate, you can format messages using markdown, HTML, or other visual layouts to enable rich, styled content in the message view.
216-
217-
{% tabs %}
218-
{% highlight C# %}
219-
220-
public class AIMessage : NotificationObject, ITextMessage
221-
{
222-
223-
private string solution;
224-
225-
/// <summary>
226-
/// Gets or sets the text to be display as the message.
227-
/// </summary>
228-
public string Solution
229-
{
230-
get
231-
{
232-
return this.solution;
233-
}
234-
set
235-
{
236-
this.solution = value;
237-
RaisePropertyChanged(nameof(Solution));
238-
}
239-
}
240-
241-
private Author author;
242-
243-
/// <summary>
244-
/// Gets or sets the author to be display in the message.
245-
/// </summary>
246-
public Author Author
247-
{
248-
get { return author; }
249-
set
250-
{
251-
author = value;
252-
RaisePropertyChanged(nameof(Author));
253-
}
254-
}
255-
256-
private DateTime dateTime;
257-
258-
/// <summary>
259-
/// Gets or sets the date and time details when the message was created.
260-
/// </summary>
261-
public DateTime DateTime
262-
{
263-
get { return dateTime; }
264-
set
265-
{
266-
dateTime = value;
267-
RaisePropertyChanged(nameof(DateTime));
268-
}
269-
}
270-
271-
private string text;
272-
273-
/// <summary>
274-
/// Gets or sets the text to be display as the message.
275-
/// </summary>
276-
public string Text
277-
{
278-
get { return text; }
279-
set { text = value; RaisePropertyChanged(nameof(Text)); }
280-
}
281-
}
282-
283-
public class ViewTemplateSelector : DataTemplateSelector
284-
{
285-
public DataTemplate AITemplate { get; set; }
286-
287-
public override DataTemplate SelectTemplate(object item, DependencyObject container)
288-
{
289-
if (item is AIMessage)
290-
{
291-
return AITemplate;
292-
}
293-
return null;
294-
}
295-
}
296-
297-
{% endhighlight %}
298-
{% endtabs %}
220+
This approach lets you tailor the appearance of assistant messages without modifying your data model.
299221

300222
{% tabs %}
301223
{% highlight xaml %}
302-
303224
<Page
304225
x:Class="GettingStarted.MainPage"
305226
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
@@ -368,7 +289,87 @@ public class ViewTemplateSelector : DataTemplateSelector
368289
</Grid>
369290
</Page>
370291

371-
{% endhighlight %}
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 %}
372373
{% endtabs %}
373374

374375
![WPF AI AssistView control ViewTemplateSelector](aiassistview_images/wpf_aiassistview_openai1.png)

0 commit comments

Comments
 (0)