Property is not updating in silverlight - silverlight-4.0

Property is not updating in silverlight..
Public Property CurrentUser As BCOMSUser
Get
' Return _currentUser
Return BCOMSCurrentUser.BCOMSUser
End Get
Set(value As BCOMSUser)
_currentUser = value
OnPropertyChanged(Function(x) x.CurrentUser)
End Set
End Property
I am overwriting the property like this but sill its holsing the previous values.
Dim usr As BCOMSUser = e.Result.Response
CurrentUser = usr
<sdk:Label Grid.Row="21" Grid.Column="0" Margin="0,0,5,0" HorizontalAlignment="Right" Name="lblRoles" VerticalAlignment="Top" Width="120" Content="Roles:" />
<sdk:DataGrid Grid.Row="21" Grid.Column="1" AutoGenerateColumns="False" Height="150" HorizontalAlignment="Left" Name="UserRolesDataGrid" VerticalAlignment="Top" Width="182" ItemsSource="{Binding Path=PagedUserRoles}">
<sdk:DataGrid.Columns>
<sdk:DataGridTextColumn Header="Role" Binding="{Binding Path=RoleName}" Width="105" />
<sdk:DataGridCheckBoxColumn Header="Subscribe" Binding="{Binding Path=IsSubscribed}" Width="75" />
</sdk:DataGrid.Columns>
</sdk:DataGrid>
<sdk:DataPager Name="UserRolesDataPager" Grid.Row="22" Grid.Column="1" PageSize="10" HorizontalAlignment="Left" VerticalAlignment="Center" HorizontalContentAlignment="Center" Width="182" Source="{Binding Path=PagedUserRoles}"></sdk:DataPager>
<StackPanel Grid.Row="24" Grid.Column="1" Orientation="Horizontal" >
<Button Content="Save Changes" Height="23" HorizontalAlignment="Left" Margin="0,0,0,0" Name="btnSaveDetailChanges" VerticalAlignment="Top" Width="Auto" Command="{Binding Path=SaveDetailChangesCommand}" />
</StackPanel>
Code Behind :
Case UserMaintenanceViewModel.CommandNameOf(Function(x) x.UpdateUserCommand),
UserMaintenanceViewModel.CommandNameOf(Function(x) x.SaveDetailChangesCommand)
After Updating the Role I fetch the Current Updated Role and I am Binding to the Property in the callback but it's not updating..
Private Sub GetBCOMSUserCallback(ByVal sender As Object, ByVal e As GetBCOMSUserCompletedEventArgs)
Try
If Not e.Result.IsFault Then
Dim usr As BCOMSUser = e.Result.Response
CurrentUser = usr
'SetupMenu()
OnCommandCompleted(Function(x) x.GetBCOMSUserCommand)
Else
OnError(New BCOMSException With {
.GeneralErrorMessage = "Fail to retrieve User.",
.DetailErrorMessage = e.Result.FaultMessage
})
End If
Catch ex As Exception
OnError(ex)
Finally
TaskSvc.RemoveCallback_GetBCOMSUser(AddressOf GetBCOMSUserCallback)
End Try
End Sub

Related

How to prevent multiple click on tab for focusing on AutoSuggestBoxView?

I have a Form in which there are many labels and textfield. So I'm navigating within the textfield or entry by clicking on tab button in my keyboard. The normal entry is getting focused on single click whereas the AutoSuggestBoxView which is a custom entry needs two clicks on tab to get focused. I don't know why I'm facing this issue. I have applied tabindex as 0 and -1 but still it is not working.This is my xaml code
<CtrlUC:UCCurrentLocation Grid.Row="0" HeightRequest="32" Grid.Column="0" Latitude="{Binding FieldsData.fromlatitude.Value,Mode=TwoWay}" Longitude="{Binding FieldsData.fromlongitude.Value,Mode=TwoWay}" Grid.RowSpan="2" Grid.ColumnSpan="2" HorizontalOptions="Fill" VerticalOptions="Fill" WidthRequest="400" Title="Location" LatitudeTitle="Latitude" LongitudeTitle="Longitude" ButtonText="Location" IsEditable="False" IsVisible="{Binding Path=FieldsData.FromLocationControl.IsVisible, Mode=TwoWay}" IsEnabled="{Binding Path=FieldsData.IsViolationCreated.IsEnabled, Mode=TwoWay}" />
<local:AutoSuggestBoxView x:Name="FromState" Grid.Row="1" Grid.Column="2" TabIndex="-1" Grid.RowSpan="1" Grid.ColumnSpan="1" DisplayMemberPath="{Binding FieldsData.PickerFromState.Value.DisplayField}" SelectedValuePath="{Binding FieldsData.PickerFromState.Value.ValueField}" SearchMemberPath="{Binding FieldsData.PickerFromState.Value.DisplayField}" VerticalOptions="StartAndExpand" ItemsSource="{Binding Path=FieldsData.PickerFromState.Value.DataSource}" SelectedItem="{Binding Path=FieldsData.PickerFromStateSelectedItem.Value, Mode=TwoWay}" SelectedValue="{Binding Path=FieldsData.fromstatePropertyText.Value, Mode=TwoWay}" Text="{Binding Path=FieldsData.fromstatename.Value, Mode=TwoWay}" Placeholder="Enter State" IsEnabled="{Binding Path=FieldsData.IsViolationCreated.IsEnabled, Mode=TwoWay}" IsVisible="{Binding Path=FieldsData.PickerFromState.IsVisible, Mode=TwoWay}" />
<local:CCEntry Grid.Row="1" Grid.Column="3" Style="{StaticResource FormEntryStyle}" Margin="0,0,10,3" Text="{Binding Path=FieldsData.fromstatecode.Value, Mode=TwoWay}" Grid.RowSpan="1" Grid.ColumnSpan="1" HorizontalOptions="Fill" VerticalOptions="Fill" IsEnabled="{Binding Path=FieldsData.fromstatecode.IsEnabled, Mode=TwoWay}" IsVisible="{Binding Path=FieldsData.LblFromStateCodeValue.IsVisible, Mode=TwoWay}" />
<local:AutoSuggestBoxView x:Name="FromCity" Grid.Row="1" Grid.Column="4" TabIndex="" Grid.RowSpan="1" Grid.ColumnSpan="1" DisplayMemberPath="{Binding FieldsData.PickerFromCity.Value.DisplayField}" SelectedValuePath="{Binding FieldsData.PickerFromCity.Value.ValueField}" SearchMemberPath="{Binding FieldsData.PickerFromCity.Value.DisplayField}" VerticalOptions="StartAndExpand" ItemsSource="{Binding Path=FieldsData.PickerFromCity.Value.DataSource}" SelectedItem="{Binding Path=FieldsData.PickerFromCitySelectedItem.Value, Mode=TwoWay}" SelectedValue="{Binding Path=FieldsData.fromcityPropertyText.Value, Mode=TwoWay}" Text="{Binding Path=FieldsData.fromcityname.Value, Mode=TwoWay}" Placeholder="Enter City" IsEnabled="{Binding Path=FieldsData.IsViolationCreated.IsEnabled, Mode=TwoWay}" IsVisible="{Binding Path=FieldsData.PickerFromCity.IsVisible, Mode=TwoWay}" />
<local:CCEntry Grid.Row="1" Grid.Column="5" Style="{StaticResource FormEntryStyle}" Margin="0,0,10,3" Text="{Binding Path=FieldsData.fromcitycode.Value, Mode=TwoWay}" Grid.RowSpan="1" Grid.ColumnSpan="1" HorizontalOptions="Fill" VerticalOptions="Fill" IsEnabled="{Binding Path=FieldsData.fromstatecode.IsEnabled, Mode=TwoWay}" IsVisible="{Binding Path=FieldsData.LblFromCityCodeValue.IsVisible, Mode=TwoWay}" />
<local:AutoSuggestBoxView x:Name="FromCounty" Grid.Row="1" Grid.Column="6" TabIndex="0" Grid.RowSpan="1" Grid.ColumnSpan="1" DisplayMemberPath="{Binding FieldsData.PickerFromcounty.Value.DisplayField}" SelectedValuePath="{Binding FieldsData.PickerFromcounty.Value.ValueField}" SearchMemberPath="{Binding FieldsData.PickerFromcounty.Value.DisplayField}" VerticalOptions="StartAndExpand" ItemsSource="{Binding Path=FieldsData.PickerFromcounty.Value.DataSource}" SelectedItem="{Binding Path=FieldsData.PickerFromCountySelectedItem.Value, Mode=TwoWay}" SelectedValue="{Binding Path=FieldsData.fromcountyPropertyText.Value, Mode=TwoWay}" Text="{Binding Path=FieldsData.fromcountyname.Value, Mode=TwoWay}" Placeholder="Enter County" IsEnabled="{Binding Path=FieldsData.IsViolationCreated.IsEnabled, Mode=TwoWay}" IsVisible="{Binding Path=FieldsData.PickerFromcounty.IsVisible, Mode=TwoWay}" />
<local:CCEntry Grid.Row="1" Grid.Column="7" Style="{StaticResource FormEntryStyle}" Margin="0,0,10,3" Text="{Binding Path=FieldsData.fromcountycode.Value, Mode=TwoWay}" Grid.RowSpan="1" Grid.ColumnSpan="1" HorizontalOptions="Fill" VerticalOptions="Fill" IsEnabled="{Binding Path=FieldsData.fromstatecode.IsEnabled, Mode=TwoWay}" IsVisible="{Binding Path=FieldsData.LblFromCountyCodeValue.IsVisible, Mode=TwoWay}" />
So as you can see in code the normal entry like CCEntry takes only one tab click. But the custom entry AutoSuggestBoxView takes two clicks on tab to get focused.I have no clue how to fix this. Any suggestions?
There is only one way to avoid multiple clicks in xamarin.forms is you have to use a boolean flag as shown below
public class MyPage : ContentPage
{
public isClicked = false;
public MyPage()
{
InitializeComponent();
}
protected override void OnAppearing()
{
base.OnAppearing();
isClicked = false;
}
private void ItemTapped(object sender, System.EventArgs e)
{
if(isClicked)
return;
isClicked = true;
//Do your work here
}
}
I am using this way to avoid multiple clicks.

WP7 - Is it possible to selecte the item from list on button click time

I want to select the list item when I click the button(Which is inside the list box for every row).
Now I have try like this:-
<ListBox Height="444"
ItemsSource="{Binding StudentDetails,Mode=TwoWay}"
HorizontalAlignment="Left" Margin="2,34,0,0"
Name="listBox1" VerticalAlignment="Top"
Width="476" BorderBrush="#00410D0D"
SelectedIndex="{Binding MemberPrivacy,Mode=TwoWay}"
SelectedItem="{Binding SelectedStudent, Mode=TwoWay}">
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Gray" Padding="5" BorderThickness="1">
<StackPanel Orientation="Horizontal">
<Border BorderBrush="Wheat" BorderThickness="1">
<Image Name="ListPersonImage" Source="{Binding PersonImage}" Height="100" Width="100" Stretch="Uniform" Margin="10,0,0,0"/>
</Border>
<TextBlock Text="{Binding FirstName}" Name="firstName" Width="200" Foreground="White" Margin="10,10,0,0" FontWeight="SemiBold" FontSize="22" />
<Image Height="50" Source="{Binding addImage}" HorizontalAlignment="Left" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="50" />
<Button Margin="-100,0,0,0" Height="80" Width="80" DataContext="{Binding DataContext, ElementName=listBox1}" Command="{Binding addPerson}" >
<Button.Background>
<ImageBrush ImageSource="{Binding addImage, Converter={StaticResource pathToImageConverter}}" Stretch="Fill" />
</Button.Background>
</Button>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
My View Model:-
public ListBoxEventsViewModel()
{
addPerson = new ReactiveAsyncCommand();
addPerson.Subscribe(x =>
{
MessageBox.Show("Test Button Selected..");
});
}
Here I can show the message box when I click the button. But I can not select the list item. Please let me know to solve this problem.
Thanks in advance.
View Model:-
List box selected Item:-
public ListBoxEventsModel _SelectedStudent;
public ListBoxEventsModel SelectedStudent
{
get { return _SelectedStudent; }
set
{
this.RaiseAndSetIfChanged(x => x.SelectedStudent, value);
MessageBox.Show("Selected index==>" + SelectedStudent.FirstName);
}
}
Here it showing the selected name when I click the list item. But this same thing I want to write it for the button(addImage)
Bind the SelectedItem on the ListBox to a "SelectedItem" property on the ViewModel.
eg SelectedItem="{Binding SelectedItem, Mode=TwoWay}"
then on the view model just add a property of SelectedItem, then you can just set that from in your subscribe.

validate a cell based on another cell value in datagrid in silverlight

PFB the code for datagrid in our silverlight app,i need to validate the column AttributeValue in each row based on other column value DatatypeName, for example the DatatypeNamecolumn value for a particular row is int the AttributeValue column in the same row should allow user only int ,if user enters other than int the cell should throw validation exception.Please help
<sdk:DataGrid Margin="0,0,0,50" Grid.Row="1" Grid.Column="0" RowStyle="{StaticResource DataGridRowStyle1}" Style="{StaticResource DataGridStyle1}" IsReadOnly="True" Foreground="{StaticResource GrayBrush}" HorizontalScrollBarVisibility="Hidden" Name="dgKpiAttributes" MinHeight="5" VerticalAlignment="Stretch" FontSize="13.333" FontFamily="Segoe UI" AutoGenerateColumns="False" GridLinesVisibility="None" >
<sdk:DataGrid.Columns>
<sdk:DataGridTemplateColumn Header=" " >
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<CheckBox x:Name="chkSelect"
VerticalAlignment="Center" IsChecked="False" HorizontalAlignment="Center" HorizontalContentAlignment="Center"/>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
<sdk:DataGridTemplateColumn Header="AttributeName" SortMemberPath="AttributeName" Width="50*" >
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel VerticalAlignment="Center">
<TextBlock x:Name="txtAttributeName" TextWrapping="Wrap" Padding="4" Text="{Binding AttributeName}" HorizontalAlignment="Center" VerticalAlignment="Center" />
</StackPanel>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
<sdk:DataGridTemplateColumn Header="AttributeValue" SortMemberPath="AttributeValue" Width="80*" >
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel VerticalAlignment="Center">
<TextBox x:Name="AttributeValue" Margin="0,0,10,0" HorizontalAlignment="Stretch" Text="{Binding AttributeValue}" TextWrapping="Wrap" />
</StackPanel>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
<sdk:DataGridTemplateColumn Header="DataType" SortMemberPath="DataTypeName" Width="50*">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<StackPanel VerticalAlignment="Center">
<TextBox x:Name="DatatypeName" HorizontalAlignment="Stretch" TextWrapping="Wrap" IsEnabled="False" Text="{Binding DataTypeName}" />
</StackPanel>
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
</sdk:DataGrid.Columns>
</sdk:DataGrid>
Well, from your code I can see your class is like this (correct me if I'm mistaken):
class MyClass
{
public string AttributeName {get;set;}
public string AttributeValue {get;set;}
public string DatatypeName {get;set;}
}
In silverligth, I suppose there is a way to check another cells in the same row in a datagrid, but since you are working with bindings, you do not need that, you can work directly in your data object:
class MyClass
{
public string AttributeName {get;set;}
public string DatatypeName {get;set;}
private string _AttributeValue;
public string AttributeValue {
get{
return _AttributeValue;
}
set{
if (validate(DatatypeName,value)){
//Do something if validation is a success
_AttributeValue = value;
}
else{
//Do something if validation fails
}
}
}
bool validate(string typename,string value){
//do your validation, return true or false
return true
}
}
This way you do not need to concern yourself with traversing the UI, only with the data.

Sample Callisto Settings Flyout in VB

Does anyone have a sample for adding a Callisto settingsflyout in VB? There are several samples in CS but I can't seem to make sense of them in a VB mode. I want to add one toggle switch and save it for my app to reference. I am using VB and XAML.
This is what I use in my App.XAML.VB:
Private Sub addSettingsScenarioAdd()
AddHandler SettingsPane.GetForCurrentView.CommandsRequested, AddressOf onCommandsRequested
End Sub
Private Sub onSettingsCommand(command As IUICommand)
Dim settingsCommand As SettingsCommand = DirectCast(command, SettingsCommand)
Dim rootFrame As Frame = Window.Current.Content
rootFrame.Navigate(GetType(Page1))
End Sub
Private Sub onCommandsRequested(sender As SettingsPane, args As SettingsPaneCommandsRequestedEventArgs)
Dim handler1 As New UICommandInvokedHandler(AddressOf onSettingsCommand)
Dim about = New SettingsCommand("about", "About", Sub(handler)
Dim aboutpane = New SettingsFlyout()
aboutpane.Content = New AboutPanel()
aboutpane.IsOpen = True
aboutpane.HeaderText = "About"
aboutpane.Background = New SolidColorBrush(Colors.White)
UserSettings.Values("isAboutOpen") = "yes"
End Sub)
args.Request.ApplicationCommands.Add(about)
End Sub
And then use the SettingsFlyout controls to collect and store settings (e.g. you could store in isolated storage or setup properties in your App.XAML.VB that can be changed from your flyout controls.
That should get you started (you obviously also need to create the controls for the flyouts, which just need to be usercontrols that are the right size/shape on the page. Here is an example of my 'aboutpanel' control:
<UserControl
x:Class="ThisApp.AboutPanel"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:FootballHub"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="480" Width="260" ManipulationMode="None">
<StackPanel >
<Grid Background="White" Margin="0,0,0,0" ManipulationMode="None">
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
<RowDefinition Height="50"/>
<RowDefinition Height="250"/>
</Grid.RowDefinitions>
<TextBlock x:Name="VersionAndPublisherText" HorizontalAlignment="Left" Margin="10,0,0,0" Foreground="{StaticResource MainColour}" TextWrapping="Wrap" VerticalAlignment="Top" Height="40" Width="240" FontSize="12" Grid.Row="1" Text="Textblock" />
<TextBlock x:Name="SupportHeadingText" Grid.Row="2" FontFamily="Global User Interface" FontSize="14" FontWeight="Bold" Foreground="Black" Margin="10,0" Text="Textblock" VerticalAlignment="Bottom" />
<TextBlock x:Name="SupportText" Grid.Row="3" FontFamily="Global User Interface" FontSize="12" Foreground="#FF045DF6" HorizontalAlignment="Right" Width="240" Margin="0,0,10,0" Height="50" VerticalAlignment="Top" Text="Textblock" TextWrapping="Wrap" FontStyle="Italic" />
<TextBlock x:Name="MainHeadingText" HorizontalAlignment="Left" Margin="10,0,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Bottom" Width="240" FontWeight="Bold" FontFamily="Global User Interface" Foreground="Black" FontSize="14"/>
<TextBlock x:Name="PrivacyHeadingText" Grid.Row="4" FontFamily="Global User Interface" FontSize="14" FontWeight="Bold" Foreground="Black" Margin="10,0" Text="Textblock" VerticalAlignment="Bottom" />
<TextBlock x:Name="PrivacyText" Grid.Row="5" FontFamily="Global User Interface" FontSize="12" Foreground="{StaticResource MainColour}" HorizontalAlignment="Right" Width="240" Margin="0,0,10,0" Height="211" VerticalAlignment="Top" Text="Textblock" TextWrapping="Wrap" />
</Grid>
</StackPanel>
Add your buttons and options, etc. to that.
I also use handlers to detect when my panels are opening/closing so I can apply settings, etc.:
AddHandler Me.Unloaded, AddressOf closing_AboutPanel
AddHandler Me.Loaded, AddressOf opening_AboutPanel
That should cover most of it. When adding code to your panels you can just treat them like any other page or control in terms of getting input and storing settings.

Silverlight- DataGrid control - Selection Changed event interfering with sorting

I'm currently playing with the Silverlight(Beta 2) Datagrid control. Before I wired up the SelectionChanged event, the grid would sort perfectly by clicking on the header. Now, when the grid is clicked, it will fire the SelectionChanged event when I click the header to sort. Is there any way around this?
In a semi-related topic, I'd like to have the SelectionChanged event fire when I click on an already selected item (so that I can have a pop-up occur to allow the user to edit the selected value). Right now, you have to click on a different value and then back to the value you wanted in order for it to pop up. Is there another way?
Included is my code.
The Page:
<UserControl x:Class="WebServicesApp.Page"
xmlns="http://schemas.microsoft.com/client/2007"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
Width="1280" Height="1024" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">
<Grid x:Name="LayoutRoot" Background="White">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" x:Name="OurStack" Orientation="Vertical" Margin="5,5,5,5">
<ContentControl VerticalAlignment="Center" HorizontalAlignment="Center">
<StackPanel x:Name="SearchStackPanel" Orientation="Horizontal" Margin="5,5,5,5">
<TextBlock x:Name="SearchEmail" HorizontalAlignment="Stretch" VerticalAlignment="Center" Text="Email Address:" Margin="5,5,5,5" />
<TextBox x:Name="InputText" HorizontalAlignment="Stretch" VerticalAlignment="Center" Width="150" Height="Auto" Margin="5,5,5,5"/>
<Button x:Name="SearchButton" Content="Search" Click="CallServiceButton_Click" HorizontalAlignment="Center" VerticalAlignment="Center" Width="75" Height="Auto" Background="#FFAFAFAF" Margin="5,5,5,5"/>
</StackPanel>
</ContentControl>
<Grid x:Name="DisplayRoot" Background="White" ShowGridLines="True"
HorizontalAlignment="Center" VerticalAlignment="Center" MaxHeight="300" MinHeight="100" MaxWidth="800" MinWidth="200"
ScrollViewer.HorizontalScrollBarVisibility="Visible" ScrollViewer.VerticalScrollBarVisibility="Visible">
<data:DataGrid ItemsSource="{Binding ''}" CanUserReorderColumns="False" CanUserResizeColumns="False"
AutoGenerateColumns="False" AlternatingRowBackground="#FFAFAFAF" SelectionMode="Single"
HorizontalAlignment="Center" VerticalAlignment="Center" Margin="5,5,5,5" x:Name="IncidentGrid" SelectionChanged="IncidentGrid_SelectionChanged">
<data:DataGrid.Columns>
<data:DataGridTextColumn DisplayMemberBinding="{Binding Address}" Header="Email Address" IsReadOnly="True" /> <!--Width="150"-->
<data:DataGridTextColumn DisplayMemberBinding="{Binding whereClause}" Header="Where Clause" IsReadOnly="True" /> <!--Width="500"-->
<data:DataGridTextColumn DisplayMemberBinding="{Binding Enabled}" Header="Enabled" IsReadOnly="True" />
</data:DataGrid.Columns>
</data:DataGrid>
</Grid>
</StackPanel>
<Grid x:Name="EditPersonPopupGrid" Visibility="Collapsed">
<Rectangle HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Opacity="0.765" Fill="#FF8A8A8A" />
<Border CornerRadius="30" Background="#FF2D1DCC" Width="700" Height="400" HorizontalAlignment="Center" VerticalAlignment="Center" BorderThickness="1,1,1,1" BorderBrush="#FF000000">
<StackPanel x:Name="EditPersonStackPanel" Orientation="Vertical" Background="White" HorizontalAlignment="Center" VerticalAlignment="Center" Width="650" >
<ContentControl>
<StackPanel x:Name="EmailEditStackPanel" Orientation="Horizontal">
<TextBlock Text="Email Address:" Width="200" Margin="5,0,5,0" />
<TextBox x:Name="EmailPopupTextBox" Width="200" />
</StackPanel>
</ContentControl>
<ContentControl>
<StackPanel x:Name="AppliesToDropdownStackPanel" Orientation="Horizontal" Margin="2,2,2,0">
<TextBlock Text="Don't send when update was done by:" />
<StackPanel Orientation="Vertical" MaxHeight="275" MaxWidth="350" >
<TextBlock x:Name="SelectedItemTextBlock" TextAlignment="Right" Width="200" Margin="5,0,5,0" />
<Grid x:Name="UserDropDownGrid" MaxHeight="75" MaxWidth="200" Visibility="Collapsed" ScrollViewer.VerticalScrollBarVisibility="Visible" ScrollViewer.HorizontalScrollBarVisibility="Hidden" >
<Rectangle Fill="White" />
<Border Background="White">
<ListBox x:Name="UsersListBox" SelectionChanged="UsersListBox_SelectionChanged" ItemsSource="{Binding UserID}" />
</Border>
</Grid>
</StackPanel>
<Button x:Name="DropDownButton" Click="DropDownButton_Click" VerticalAlignment="Top" Width="25" Height="25">
<Path Height="10" Width="10" Fill="#FF000000" Stretch="Fill" Stroke="#FF000000" Data="M514.66669,354 L542.16669,354 L527.74988,368.41684 z" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="1,1,1,1"/>
</Button>
</StackPanel>
</ContentControl>
<TextBlock Text="Where Clause Condition:" />
<TextBox x:Name="WhereClauseTextBox" Height="200" Width="800" AcceptsReturn="True" TextWrapping="Wrap" />
<ContentControl>
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<Button x:Name="TestConditionButton" Content="Test Condition" Margin="5,5,5,5" Click="TestConditionButton_Click" />
<Button x:Name="Save" Content="Save" HorizontalAlignment="Right" Margin="5,5,5,5" Click="Save_Click" />
<Button x:Name="Cancel" Content="Cancel" HorizontalAlignment="Right" Margin="5,5,5,5" Click="Cancel_Click" />
</StackPanel>
<TextBlock x:Name="TestContitionResults" Visibility="Collapsed" />
</StackPanel>
</ContentControl>
</StackPanel>
</Border>
</Grid>
</Grid>
And the call that occurs when the grid's selection is changed:
Private Sub IncidentGrid_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
If mFirstTime Then
mFirstTime = False
Else
Dim data As SimpleASMX.EMailMonitor = CType(IncidentGrid.SelectedItem, SimpleASMX.EMailMonitor)
Dim selectedGridItem As SimpleASMX.EMailMonitor = Nothing
If IncidentGrid.SelectedItem IsNot Nothing Then
selectedGridItem = CType(IncidentGrid.SelectedItem, SimpleASMX.EMailMonitor)
EmailPopupTextBox.Text = selectedGridItem.Address
SelectedItemTextBlock.Text = selectedGridItem.AppliesToUserID
WhereClauseTextBox.Text = selectedGridItem.whereClause
IncidentGrid.SelectedIndex = mEmailMonitorData.IndexOf(selectedGridItem)
End If
If IncidentGrid.SelectedIndex > -1 Then
EditPersonPopupGrid.Visibility = Windows.Visibility.Visible
Else
EditPersonPopupGrid.Visibility = Windows.Visibility.Collapsed
End If
End If
End Sub
Sorry if my code is atrocious, I'm still learning Silverlight.
That looks like a Silverlight bug to me. I've just tried it and what's happening on my end is that the SelectionChanged event fires twice when you click the column header and to make matters worse, the index of the selected item doesn't stay synched with the currently selected item.
I'd suggest you work your way around it by using the knowledge that the first time SelectionChanged fires, the value of the datagrid's SelectedItem property will be null
Here's some sample code that at least lives with the issue. Your SelectionChanged logic can go in the if clause.
public partial class Page : UserControl
{
private Person _currentSelectedPerson;
public Page()
{
InitializeComponent();
List<Person> persons = new List<Person>();
persons.Add(new Person() { Age = 5, Name = "Tom" });
persons.Add(new Person() { Age = 3, Name = "Lisa" });
persons.Add(new Person() { Age = 4, Name = "Sam" });
dg.ItemsSource = persons;
}
private void SelectionChanged(object sender, EventArgs e)
{
DataGrid grid = sender as DataGrid;
if (grid.SelectedItem != null)
{
_currentSelectedPerson = grid.SelectedItem as Person;
}
else
{
grid.SelectedItem = _currentSelectedPerson;
}
}
}
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
}
Frozen Columns in Silverlight DataGrid..
http://dotnetdreamer.wordpress.com/2009/01/31/silverlight-2-datagrid-frozen-columns/
There's a bugfix for the first issue you mentioned (selection changed event getting fired on resort).
See the following URL for Microsoft's patch:
http://www.microsoft.com/downloads/details.aspx?familyid=084A1BB2-0078-4009-94EE-E659C6409DB0&displaylang=en
This worked, but now if I sort twice, on the first one it sorts, and then does the popup as the first selected item of the grid . If I close the popup grid, and then try to sort a second time, it stack overflows, and crashes firefox out.
I'm thinking I may need to rethink working in silverlight until the system gets a bit more stable.
Thanks for the answer Hovito!