xaml - Create Resources with UI - xaml

normally if i create a template for an ListView Item or something else, I'm not able to see the result until i start my application and fill the List with Items.
Something like that:
<ListView ItemsSource="{Binding}">
<ListView.ItemTemplate>
<DataTemplate>
<Button>Complex DataTemplate</Button>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Well i want to see a preview of my ItemTemplate while I create it, but I do not know how...

You can create design-time data to bind to so the list can fill with data in the designer. See Displaying data in the designer for how to set this up.

Related

How to make a TextBox have focus so user can start typing

I have a TextBox which I would like to have the focus when the 'view' loads. When I say focus, I mean that the user can start typing straight away and text appears in the focused TextBox.
I've seen so many questions similar here on SO, and they pretty much all have the same answer which is use Dependency Property: FocusManager.FocusedElement
The issue I have is, whilst this does select the control, it doesn't allow the user to type! Normally when you select a TextBlock you get a blinking caret. Using the following, I see a non-blinking caret and I cannot enter text without selecting the textbox (which defeats the point)
<TextBox Margin="10"
Text="{Binding Threshold,
UpdateSourceTrigger=PropertyChanged,
ValidatesOnDataErrors=True }"
FocusManager.FocusedElement="{Binding RelativeSource={RelativeSource Self}}"/>
Try moving the declaration to the MainContainer in your XAML
<Grid x:Name="MainContainer"
FocusManager.FocusedElement="{Binding ElementName=txtbox}"
...
>
...
<TextBox Grid.Row="..." Grid.Column="..."
x:Name="txtbox">
</TextBox>
...
</Grid>

Call text from another file into a textblock

Im making a flash card like app in xaml, I created a textblock and was wondering how can I call text in a seperate .txt file so I dont have to write out the whole definition in the same page.
<Textblock Height="150" TextWrapping="Wrap" Text="**how do i link this**">
Thanks
The easiest method would be to do this in the code behind. Either at page_load or triggered some other way.
I think your question is answered here: Windows Phone 8 - reading and writing in an existing txt file in the project
Using this method, I'd store your flash cards in the Assets folder and read them from there.
For your case, you would want to name your Textblock and then set the text from your code behind.
XAML:
<Textblock x:Name="tbFlashCard" Height="150" TextWrapping="Wrap" Text="**how do i link this**">
Modified code from other post:
tbFlashCard.Text = FileHelper.ReadFile(#"Assets\MyTextFile.txt");

ComboBox in Telerik.UI.Xaml.Controls.Grid.RadDataGrid

Windows 8
Visual Studio 2012 Express
Simple XAML:
<telerik:RadDataGrid ItemsSource="{Binding ProductsSource}" AutoGenerateColumns="False">
<telerik:RadDataGrid.Columns>
<telerik:DataGridTemplateColumn Header="Whatever">
<telerik:DataGridTemplateColumn.CellContentTemplate>
<DataTemplate>
<ComboBox>
<ComboBoxItem>one</ComboBoxItem>
<ComboBoxItem>two</ComboBoxItem>
<ComboBoxItem>three</ComboBoxItem>
</ComboBox>
</DataTemplate>
</telerik:DataGridTemplateColumn.CellContentTemplate>
</telerik:DataGridTemplateColumn>
</telerik:RadDataGrid.Columns>
</telerik:RadDataGrid>
The binding source is there just to populate the grid with something. In the real app I do use it.
The problem: whenever I select an item from the combobox it does not remain selected, the items appear(dropdown), selection works, but the combobox displays nothing. An out of the grid combobox works ok.
I am new at this and I am definetely missing something.
Yes, this is due to the fact that the ComboBox does not update its VisualState right after the SelectionChanged event is raised, because there is an animation in between.
Best regards,
Ivaylo

Silverlight 4 Datagrid and ContextMenu Binding to a Textbox?

I'm simply trying to add a right click context menu for cut/copy/paste to a datagrid so you can right-click on each cell.
I got the menu showing up fine, the trouble is trying to execute the command correctly
<DataTemplate x:Key="BasicTitleEditCellTemplate">
<local:DataContextPropagationGrid>
<TextBox Text="{Binding Path=Person.Name, Mode=TwoWay}" Background="White" />
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu>
<toolkit:MenuItem Header="Cut" Click="Test_Method" />
<toolkit:MenuItem Header="Copy" />
<toolkit:Separator/>
<toolkit:MenuItem Header="Paste"/>
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
</local:DataContextPropagationGrid>
</DataTemplate>
Now the problem I'm having a hard time figuring out, is when the user clicks one of the context menu items, How do I get the text from the textbox they're clicking on? Or the selected text of it rather?
In WPF it always seemed like there were ways you could get the control that the context menu is bound to, I can't figure out anyway in Silverlight to get a reference to that textbox.
How is this commonly done?
You have not provided enough information like are you using MVVM or what?
But it looks pretty simple
<toolkit:MenuItem Header="Cut" CommandParameter="{Binding YourItem}" Command="{Binding YourClickCommand}"/>

Changing the colour or checkbox in MultiselectList in Windows Phone

In my application i am using MultiselectList for selecting a list of student information. Here my issue is that, I am using a black background image for my page,
Because of this in white theme, the checkbox portion is invisible. I try to edit the template of checkbox item in Blend, but failed, while editing the template its populating a huge chunk of code in XAML.
While editing template instead of style its generating Template (I edited the Multilist Item using Blend).
In the real application i am using itemtemplate and assign the resource to this item template.
So I don't know where to assign this template, and where to edit in that template to change my checkbox colour, this is a blocker issue for me, my friend told me that without theme support the app won’t pass market place submission.
Doing what you want to do, ie. editing the color of the checkbox, depending on the theme and background selected would be too much work. Have you tried using the default styles that come with Silverlight? For example, In this case, PhoneContrastbackgroundColor would be a good choice.
XAML code
<DataTemplate x:Key="whatever">
<TextBlock Text="ItemName"/>
<CheckBox BackgroundColor="{StaticResource PhoneContrastbackgroundColor}"/>
</DataTemplate>