using autocomplete box in silverlight? - silverlight

i am currently displaying data in the radgrid controls of telerik, i want to add an autotextbox over the column named "Name". how can i do this?
my radgrid only displays data and i want that whenever user enters into textbox a list of name pops up just like in stackoverflow web site.
please help..i have been using silverlight,wcf ria services,telerik controls.

You can use the AutoComplete textbox from the Silverlight 4 Toolkit. The toolkit is an advanced set of controls that are not part of the core Visual Studio library. To download & install, you can head here. Once you have it installed, you add a project reference to System.Windows.Controls add this to your UserControl declaration:
xmlns:input="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Input"
This gives you a reference point for the Silverlight Toolkit, specifically the input controls. Once that's done, here is an example of using the autocomplete textbox:
<input:AutoCompleteBox IsTextCompletionEnabled="False" HorizontalAlignment="Left" ItemsSource="{StaticResource SampleEmployees}" SelectionChanged="OnSelectionChanged"/>
This comes directly from the documentation from the Silverlight Toolkit. Link here. Click the 'AutoCompleteBox' in the left menu (under heading: Input). Once loaded, you can view the XAML/C# by clicking on any one of the items at the bottom of the window, such as 'AutoCompleteBoxSample.xaml' or 'AutoCompleteBoxSample.xaml.cs' This should give you the start/code you're looking for.
In your case, you'll also need to create a cell template for the radgridview. Here's a quick sample of what that might look like:
<radControls:RadGridView x:Name="registerGridView"
AutoGenerateColumns="False">
<radControls:RadGridView.Columns>
<radControls:GridViewToggleRowDetailsColumn />
<radControls:GridViewDataColumn Header="Client" />
<radControls:GridViewDataColumn Header="Site" />
<radControls:GridViewDataColumn Header="Name">
<radControls:GridViewDataColumn.CellTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<input:AutoCompleteBox HorizontalAlignment="Left" ItemsSource="{Binding Names}" SelectionChanged="OnSelectionChanged"/>
</StackPanel>
</DataTemplate>
</radControls:GridViewDataColumn.CellTemplate>
</radControls:GridViewDataColumn>
</radControls:RadGridView.Columns>
</radControls:RadGridView>

Related

SciChart: Custom RolloverModifierLabel for multiple DataSeries bound from code

Before I updated to the latest version of SciChart, I had this custom rollover modifier that displayed multiple values for any given point I "rolled over".
It was implemented like this:
<sci:RolloverModifier
DrawVerticalLine="True"
ShowTooltipOn="Always"
SourceMode="AllVisibleSeries"
TooltipLabelTemplate="{StaticResource RolloverLabelTemplate}" />
RolloverLabelTemplate was a ControlTemplate:
<ControlTemplate
x:Key="RolloverLabelTemplate"
TargetType="sci:TemplatableControl">
<Grid>
...
Now the RolloverModifier.TooltipLabelTemplate is gone from the API and seems to be replaced by TooltipTemplate, which takes a DataTemplate, not a ControlTemplate. I tried making an analogous DataTemplate:
<DataTemplate
x:Key="SomeTemplate"
DataType="s:XySeriesInfo">
<Grid>
But when I try to assign it to the RolloverModifier,
<s:RolloverModifier
...
TooltipTemplate="{StaticResource SomeTemplate}" />
I get the following exception:
Unable to cast object of type
'SciChart.Charting.ChartModifiers.RolloverModifier' to type
'SciChart.Charting.Visuals.RenderableSeries.BaseRenderableSeries'.
I've tried to follow this documentation: https://www.scichart.com/documentation/v4.x/webframe.html#RolloverModifier.html
and on the topic of styling the tooltip template, it suggests to have a RolloverModifier, but to add the TooltipTemplate to the RenderableSeries:
<s:SciChartSurface.RenderableSeries>
<s:FastLineRenderableSeries s:RolloverModifier.TooltipTemplate="{StaticResource XyTooltipTemplate}"/>
</s:SciChartSurface.RenderableSeries>
<s:SciChartSurface.ChartModifier>
<s:ModifierGroup>
<s:RolloverModifier ShowTooltipOn="Always" />
</s:ModifierGroup>
</s:SciChartSurface.ChartModifier>
</s:SciChartSurface>
This is a problem for me, because I don't have the RenderableSeries defined in xaml. They are bound to the view model:
<sciVisuals:SciChartSurface
...
SeriesSource="{Binding SciSeries}">
there will be more than one, and in fact I don't even know how many. How can I customize the rollover tooltip label in this case?
In SciChart WPF v4.x or later, it is necessary to apply the TooltipTemplate to the series, because many users requested the ability to individually style series. For example a Candlestick series should have a different tooltip than a Line series.
Please see the SciChart WPF Documentation for applying a RolloverModifier TooltipTemplate in v4+:
Styling the Tooltip Item Template
SciChart by default has a number of Tooltip templates which are unique to the series type.
To change the Tooltip template, use the RolloverModifier.TooltipTemplate attached property:
<s:SciChartSurface >
<s:SciChartSurface.Resources>
<!-- Tooltip Template for an XyDataSeries binds to XySeriesInfo -->
<!-- Check out the properties on XySeriesInfo to see what you can bind to -->
<DataTemplate x:Key="XyTooltipTemplate" DataType="s:XySeriesInfo">
<StackPanel Orientation="Vertical">
<TextBlock Foreground="White">
<Run Text="Series: "/>
<Run Text="{Binding SeriesName, StringFormat='{}{0}:'}"/>
</TextBlock>
<TextBlock Foreground="White">
<Run Text="X-Value: "/>
<Run Text="{Binding FormattedXValue}"/>
</TextBlock>
<TextBlock Foreground="White">
<Run Text="Y-Value: "/>
<Run Text="{Binding FormattedYValue}"/>
</TextBlock>
</StackPanel>
</DataTemplate>
</s:SciChartSurface.Resources>
<s:SciChartSurface.RenderableSeries>
<s:FastLineRenderableSeries s:RolloverModifier.TooltipTemplate="{StaticResource XyTooltipTemplate}"/>
</s:SciChartSurface.RenderableSeries>
<s:SciChartSurface.ChartModifier>
<s:ModifierGroup>
<s:RolloverModifier ShowTooltipOn="Always" />
</s:ModifierGroup>
</s:SciChartSurface.ChartModifier>
</s:SciChartSurface>
What I suggest in order to style these despite using the MVVM API is to create your styles in XAML and apply them using the SeriesBinding MVVM API.
There is an FAQ in the SciChart WPF Documentation on how to style a tooltip when using the MVVM API here.
A lot of customers ask us how to style various attached properties used in SciChart in the MVVM API. For example, the given following attached properties, how do we convert this to the MVVM API?
The solution is simple, to use our method of Styling the RenderableSeries presented in Worked Example - Style a Series in MVVM.
Simply declare the attached properties and tooltip templates in a style in your View.
Now, apply the style using BaseRenderableSeriesViewModel.StyleKey property. SciChart will pick up the style and do the rest.
If you are still using the older, SeriesSource API (note this is now obsolete as of v4.x) then I suggest declare your style in XAML and apply it using this technique to access a style in code-behind.

Create/Modify new WPF UI components

I want to change the graphical UI elements in WPF.
For example, I want to use a kind of a stack panel, but on the other hand I want to show my details in a star, or circle, etc.
Maybe setting a bitmap as a background, but I am working with lots of Data using zoom tool.
I found tutorials, documentation only for changing attributes of "old components", but nothing to make new ones.
Great resource for WPF beginners is www.wpftutorial.net
One of the best idea of WPF is separation of concerns:
UI Control = Logic in Code/XAML + Template
Using templates in XAML we can vary representation without modifying the control.
For example, if there is a need in creation of list of items. Then we can use ListBox control:
<ListBox>
<ListBoxItem>USA</ListBoxItem>
<ListBoxItem>UK</ListBoxItem>
</ListBox>
By default LisboxItem internal part is just binded TextBlock.
Now making UI modification without changing control source code:
<ListBox ImageSource="{Binding PathToSource}">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Image Source="{StaticResource ProjectIcon}"/>
<TextBlock Text="{Binding Path=PropertyName}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
there appears image and text.
If there is a need in creating exclusive control then you can always use Custom Control.
Using raster images (e.g. PNG) is not good point, especially with zoom behaviour. If it is possible better to use vector images, that can be created in XAML or imported from SVG.

How to declare Labels in xaml for use in both WPF and Silverlight

I am working on a UserControl in a Silverlight project in visual studio 2010.
This user control uses Labels as follows:
<sdk:Label .../>
-or-
<sdk:Label>
singleObject
</sdk:Label>
-or-
<sdk:Label>stringContent</sdk:Label>
as described here
However, when I create a WPF project link it to Silverlight Library Project:
(by adding existing items (Add Link) to cs classes and the .xaml file defining the control)
I get the following error in build:
The tag 'Label' does not exist in XML namespace 'http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk'. Line 49 Position 18. myfile.xaml 49 18 MyLibraryWPF
This doc shows that labels in WPF are declared without the sdk:
like this:
<Label>
Content
</Label>
yet, I cannot change that in my Silverlight project. It will be a real waste to create a whole new project and duplicate the code to make it work.
How to make the Labels work with both Silverlight and WPF projects?
Here is a piece of Code in xaml that can be shared by WPF and Silverlight and looks like label with Background coloe:
<Border Margin="3,0,3,3" Background="#FF00B050">
<TextBlock Text="txt122" FontSize="13" FontWeight="SemiBold" Height="21" Name="label15" Width="133" ></TextBlock>
</Border>
This means that a Label cannot be used in a shared XAML.

Best way to create a list of selectable and deletable items in Windows Phone 7

I want to solve a seemingly simple task. I want to create a list of text entries where each entry is selectable (and causes navigation to another page) and when the user holds his finger over an item I want a context menu with a single option to delete that item. This is very common pattern in WP applications. For example the browser does this with favourites.
Right now I have a listbox with a textblock in the item template and I start the navigation in the SelectionChanged event:
<ListBox Name="lbSnippets" SelectionChanged="lbSnippets_SelectionChanged">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding}"></TextBlock>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ListBox>
I can think of several ways to solve the hold problem but none of them sits well with me. For example I may handle the Hold event on the TextBlock but then I will have to dig for the item related to this TextBlock. Something tells me that there should be a better way to do this as it is so common. What is the right way to solve this task?
The Silverlight toolkit for WP7 includes a ContextMenu control.
You can install the toolkit via nuget: PM> Install-Package SilverlightToolkitWP
Then you an add ContextMenus to basically any control:
<DataTemplate>
<TextBlock Text="{Binding}">
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu>
<toolkit:MenuItem Header="Delete"
Command="{Binding YourDeleteCommand}"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
</TextBlock>
</DataTemplate>
Where toolkit is an xml namespace:
xmlns:toolkit="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
You can start learning about the ContextMenu control from this article:
WP7 ContextMenu in depth | Part1: key concepts and API

How can I dynamically create a list of label and textboxes in WPF?

I am trying, and failing, to create a list of labels and text boxes in WPF. I am a ASP.NET developer and the XAML experience is slightly overwhelming me at the moment... I have Apress' Pro WPF 3.0 book infront of me and finding it zero use...
At the end of my process I want users to complete some questions that will be dynamic to that user. I have an Array of objects, with properties for a "Question" and "Answer".
I want the "Question" to appear as the label.
I've been looking at ListView controls, but this just seems to give me an Excel style grid which I am not interested in.
In the ASP.NET world I'd use a GridView, with two columns, one with a Label, the other with a TextBox. On submitting the page I'd loop through the items in the grid view to pick out the values of the textboxes, and associate back to the correct object in the Array.
Could someone please direct, or show me what controls I should be using in WPF?
Extra info;
It's a desktop WPF application using .NET 4, Visual Studio 2010.
Cheers
Stu
There's absolutely no need to use a DataGrid for something as simple as this. Using a basic ItemsControl will do what you're looking for without the overhead of such a complex control. This approach is also very easy to customize by just changing the ItemTemplate.
<ItemsControl ItemsSource="{Binding QuestionsToAnswer}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding QuestionText}"/>
<TextBox Text="{Binding AnswerText}" Grid.Column="1"/>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
I agree with Scott that DataGrid is probably the way to go. Here are some decent turotials to get you started:
http://www.c-sharpcorner.com/UploadFile/mahesh/WpfDGP109272009111405AM/WpfDGP1.aspx
http://www.wpftutorial.net/DataGrid.html

Resources