How to get the value of a checkbox in data template of a combobox in datagrid in silverlight4 - silverlight-4.0

I have a combobox inside a datagrid in silverlight4. I have placed a check box inside data template of combobox to make combobox multi-selectable. Now i want to get the values for selected items in combobox.So how i can do that ?
Here is my code :
<ComboBox Name="cbxitmes" Height="23" Width="255" IsSynchronizedWithCurrentItem="False"
ItemsSource="{Binding Path=GetItems,Mode=TwoWay}"
SelectedValue="{Binding Mode=TwoWay, Path=myname}" SelectedValuePath="myvalue">
<ComboBox.ItemTemplate>
<DataTemplate>
<CheckBox Content="{Binding myname}" ></CheckBox>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Please Help me guys.
Thanks,

Take a look at this example, it might help http://www.codeproject.com/Tips/452756/Add-checkbox-inside-Combobox-in-Silverlight

Related

Binding from multi object in to one value in XAML

I have a ListView which have a DataTemplate like this:
<DataTemplate x:Key="FilterDataTemplate">
<StackPanel Orientation="Horizontal" Background="White" Height="50" HorizontalAlignment="Left">
<ComboBox x:Name="TermsItemComboBox" Width="160"
ItemsSource="{Binding ItemList}" Tag="{Binding}"
DisplayMemberPath="Key" SelectionChanged="AddTermsItem_SelectionChanged"
Background="#FFD1D1D1" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" />
<TextBox x:Name="TermsInputTxt1" Text="{Binding FilterText, Mode=TwoWay}"
BorderBrush="#FF727272" Background="#FFD1D1D1" HorizontalAlignment="Left"
Width="200" FontSize="16" VerticalAlignment="Center"
Visibility="{Binding IsTxtForm, Converter={StaticResource BooleanToVisibilityConverter}}"
Height="45"/>
<TextBox x:Name="TermsInputTxt2" Text="{Binding FilterText, Mode=TwoWay}"
BorderBrush="#FF727272" Background="#FFD1D1D1" HorizontalAlignment="Left"
Width="200" FontSize="16" VerticalAlignment="Center"
Visibility="{Binding IsTxtForm, Converter={StaticResource BooleanToVisibilityConverter}}"
Height="45"/>
<Button x:Name="TrashBtn" HorizontalAlignment="Left" VerticalAlignment="Stretch"
BorderBrush="#FF575757" Foreground="#FF494949" BorderThickness="2" Tapped="TrashBtn_Tapped"
Style="{StaticResource DiscardAppBarButtonStyle}" Height="45" Width="55"
RenderTransformOrigin="0.5,0.5">
<Button.RenderTransform>
<CompositeTransform ScaleX="-1" />
</Button.RenderTransform>
</Button>
</StackPanel>
It's have a combobox and two TextBox. At default, the combobox don's show anything, just a blank item, I want when user type some text to the TermsInputTxt1 or TermsInputTxt2, the combobox will select the first item.
I try to bind the selectedindex of combobox with the lenght of those two textbox with a converter but look like XAML doesn't support multi binding like that.
Any suggest? Thank you!
So, this is a bit of a difficult situation. You have a couple of ways of going about it:
Bind the TermsInputTxt1 and TermsInputTxt2 to the ViewModel, with the Setter on the ViewModel controlling an ObservableCollection, adding and removing items as they get set in the property.
Create a Model for each entry with a Value field (string) and bind the Terms... to accessors in the ViewModel. Then, the ComboBox items will automatically change.
I suggest doing the first one. You'll have to have a SelectedItem/SelectedIndex property in the ViewModel which the ComboBox will bind to. You may also want to change the method by which the binding on the TextBoxs are updated, either so that they are updated immediately (lots of processing) or after it loses focus (less processing, but won't update the UI immediately).

Text Align Left in an autocomplete box

I am searching how to align left the text in a AutoCompleteBox
So I details,
the result is too long for the textbox associated to autocomplete box, so, there is a missing part.
if the result is : "result of my autocomplete box", when I click and choose it, it's display on the textbox.
But the part display is : "f my autocomplete box", and I want "result of my autocomplete".
Here is my xaml :
<myControl:AutoCompleteBox x:Name="acp" Grid.Row="0" Grid.Column="1"
HorizontalAlignment="Left" VerticalAlignment="Top"
IsTabStop="False"
MinimumPrefixLength="3"
ItemTemplate="{StaticResource ItemTemplate}"
ValueMemberBinding="{Binding FullName}"
ItemsSource="{Binding Data, ElementName=MySource}"
Text="{Binding FullName, Mode=TwoWay, NotifyOnValidationError=True, ValidatesOnExceptions=True}"
Width="150"
IsTextCompletionEnabled="False"
FilterMode="None" IsDropDownOpen="True"/>
I hope i'm clear.
Thank you.
you should try This
<my:AutoCompleteBox Name="acbNames" ValueMemberBinding="{Binding FullName}">
<my:AutoCompleteBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding FullName}" TextAlignment="Left"/>
</DataTemplate>
</my:AutoCompleteBox.ItemTemplate>
</my:AutoCompleteBox>
Please use setter property of AutoCompleteBox to set text alignment like follow:
<toolkit:AutoCompleteBox.TextBoxStyle>
<Style TargetType="TextBox">
<Setter Property="TextAlignment" Value="Center"></Setter>
</Style>
</toolkit:AutoCompleteBox.TextBoxStyle>
Thanks...
Take a look at the following url http://social.msdn.microsoft.com/Forums/en-US/silverlightarchieve/thread/d41d201d-834f-4f8a-8b78-122ff08dd830/ this might help.

How to add values to checkbox inside a listbox in WP7 Silverlight

I am having problem adding values to the Checkbox.
This is how I want it to work:
When I run the application it should show the "Attendees" name and when I check the box and click "Send" it should retrieve the email address from the attendees i've checked, the email address is attached to the attendee allready, but how can I attach the email to the checkbox value ?
XAML
<ListBox Name="AppointmentResultsData" ItemsSource="{Binding Path=Attendees}" Height="400" ScrollViewer.ManipulationMode="Control" Margin="24,0,0,0" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<CheckBox Content="{Binding Path=DisplayName, Mode=OneWay}" IsChecked="true" FontSize="{StaticResource PhoneFontSizeExtraLarge}" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Button Content="Skicka" Click="SendPhoto_Click" HorizontalAlignment="Center" />
I attach the Appointments to the AppointmentsResultsData datacontext
I hope anyone can help me out!
If you use a TwoWay binding on the IsChecked property of the CheckBox then you'll be able to iterate over all items in the Attendess collection and see which were checked.
Alternatively you could use the MultiselectList from the toolkit.

How to customize the TextBlock inside the LonglistSelector

<toolkit:LongListSelector>
<toolkit:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Name}" FontSize="22" TextWrapping="Wrap" />
<TextBlock Name="Info" FontSize="18" TextWrapping="Wrap" />
</StackPanel>
</DataTemplate>
</toolkit:LongListSelector.ItemTemplate>
</toolkit:LongListSelector>
I have the above LongListSelector which selects the "Name"(Binded in the first Textblock )values from a list. I also wanted to additional text to it,for which i created one more Textblock below that. I couldn't add the text to the second TextBlock like(Info.Text="HI") because it is inside the LonglistSelector
How to give the values to the second Textblock??
Thanks
Do you mean Info is a property on the DataContext of the page and not on the current item where Name is?
If so, you can use a DataContextProxy to get to the data outside of the list item. If not, you'll have to be more clear on what you mean.

Conditionally setting colour of a bound element in XAML based on another field of datasource

I have the following item template in a WP7 listbox. My bound type has a boolean property (Status) and I would like to conditionally set the colour of the site name based on this. How would I go about doing this please?
Thanks in advance!
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,0,0,17" Width="432">
<TextBlock Text="{Binding SiteName}" TextWrapping="Wrap" />
<TextBlock Text="{Binding Url}" TextWrapping="Wrap" Margin="12,-6,12,0" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
The easiest way to do this is with a converter. Either you can have the converter return a color, or you can have two TextBlocks each with the color you want, and use a Boolean to Visibility, and one that is a reverse visibility, converters to hide/show each of the controls.
One word of caution is that converters can be slow, so sometimes it's more performant to bind to a ViewModel and on that ViewModel provide the convetered values that you need.