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

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.

Related

listVIew SelectionChanged and StorageFiles

I have a listView with StorageFile elements(as each element represents .mp3 file)
<ListView x:Name="songList" HorizontalAlignment="Left" Height="680" Background="{Binding }" ItemsSource="{Binding ListOfStorageFiles , Mode=TwoWay , UpdateSourceTrigger=PropertyChanged}" Margin="986,120,0,-80" VerticalAlignment="Top" Width="294">
<ListView.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding DisplayName}"/>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
So far I use folderPicker to get specific folder from the user and i bind all the files to the listView as a list of storageFiles. The files show up and im able to select them , but i have to change the mediaElement Source upon listView SelectionChanged. Unfortunately when i add SelectionChanged to listView the compiler tells me - Object reference not set to an instance of an object. Anyone know what cause this behavior ? Also is this the right approach for playing media files from a list(binding the storageFile to the list ).
EDIT : I probably have to use Interaction.Behaviors for EventName = "SelectionChanged" ?
I ended up with
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="SelectionChanged">
<core:InvokeCommandAction Command="{Binding OnSelectedSongFromList }" CommandParameter="{Binding ElementName=songList, Mode=TwoWay}"></core:InvokeCommandAction>
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
Then in the VM i use the list to :
ListOfMedia.MoveTo((uint)asf.SelectedIndex);

DataBinding ListView ItemTemplate UserControl

I have a ListView on my Windows Universal page. I am using a UserControl to define my ItemTemplate so that I can use the RelativePanel and VisualStateManager to control how my items appear depending on the screen size...
<ListView ItemsSource="{Binding Path=AllThings}"
ItemContainerStyle="{StaticResource ListViewItemStyle}">
<ListView.ItemTemplate>
<DataTemplate>
<local:CrossingControl />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
I have a button in my UserControl where I want to bind its Command to a command property in the ViewModel that is the DataContext of the list itself...
<UserControl ...>
<RelativePanel>
<StackPanel x:Name="crossedEntryPanel">
<Button Command="{Binding DataContext.DeleteCommand,
RelativeSource={RelativeSource Mode=TemplatedParent}}"
CommandParameter="{Binding}"
I have tried using the ElementName binding, but it doesn't seem to work (I suppose because my listview element name is defined in another xaml file). I have also tried the above RelativeSource binding, but that doesn't seem to work either. How can I bind this properly?
You can make use of Tag property to save the DataContext of ListView and use it in UserControl
Here how it is done
<ListView ItemsSource="{Binding Path=AllThings}" x:Name="listview"
ItemContainerStyle="{StaticResource ListViewItemStyle}">
<ListView.ItemTemplate>
<DataTemplate>
<local:CrossingControl Tag="{Binding DataContext,ElementName=listview}" />
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
<UserControl x:Name="usercontrol" ...>
<RelativePanel>
<StackPanel x:Name="crossedEntryPanel">
<Button Command="{Binding Tag.DeleteCommand,ElementName=usercontrol}"
CommandParameter="{Binding}"
RelativeSource={RelativeSource Mode=TemplatedParent}}":- this points to controltemplate of button

How to change listpicker dropdown ItemTemplate background?

I have a Windows Phone 8 listpicker that I'm trying to change the background color of, however, it only seems to change the item background and not the dropdown box background as you can see in the screen capture. The dropdown box seems to be binded to the WP8 theme. How can I change the background of the entire dropdown box and not just each individual item?
<toolkit:ListPicker x:Name="BackgroundListPicker" Background="Black" ItemsSource="{Binding BackgroundsList}">
<toolkit:ListPicker.ItemTemplate >
<DataTemplate x:Name="BackgroundItemTemplate" >
<Grid HorizontalAlignment="Stretch" Background="Black" VerticalAlignment="Stretch" Margin="0,0,0,0">
<StackPanel Orientation="Horizontal">
<Image Source="{Binding BackgroundThumb}" Width="30" Height="30" HorizontalAlignment="Left" />
<TextBlock Text="{Binding BackgroundName}" Foreground="White" Margin="12,0,0,0" HorizontalAlignment="Right"/>
</StackPanel>
</Grid>
</DataTemplate>
</toolkit:ListPicker.ItemTemplate>
</toolkit:ListPicker>
So your issue was that you were attempting to apply an image to an item. When you needed to hit the control itself that the items populate via ItemsPresenter so by pulling out the default style template for the control, and either making a place to pass in your image for an instance, or placing one directly into the template itself. You get your resulting background image for the ListPicker background to fall behind the items populating it.
Glad you found your remedy! Cheers.

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

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

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.