How to show custom dialog from Callisto WinRT toolkit? - xaml

My question is just like that. How should I show the CustomDialog control from Callisto toolkit? I have the following xaml:
<controls:LayoutAwarePage
x:Name="pageRoot"
x:Class="HeronClientWindowsStore.Views.SuggestEventDialogPage"
DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:HeronClientWindowsStore.Views"
xmlns:controls="using:HeronClientWindowsStore.Controls"
xmlns:callisto="using:Callisto.Controls"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Page.Resources>
</Page.Resources>
<callisto:CustomDialog
x:FieldModifier="public"
x:Name="suggestEventDialog"
Width="300" Height="500"
Title="Suggest an Event"
Background="Teal"
BackButtonVisibility="Visible">
<StackPanel>
<TextBlock
Margin="0,0,0,8"
Text="Suggest an event that should be added to Heron."
FontSize="14.6667"
FontWeight="SemiLight"
TextWrapping="Wrap" />
<TextBlock
Margin="0,0,0,8"
FontSize="14.6667"
FontWeight="SemiLight"
Text="Event URL" />
<callisto:WatermarkTextBox
HorizontalAlignment="Left"
Watermark="http://www.example.com"
Width="400"
Height="35" />
<StackPanel
Margin="0,20,0,0"
HorizontalAlignment="Right"
Orientation="Horizontal">
<Button Content="OK" Width="90" Margin="0,0,20,0" />
<Button Content="CANCEL" Width="90" />
</StackPanel>
</StackPanel>
</callisto:CustomDialog>
It doesn't show and I can't see any Method for triggering it.

You have to use IsOpen property to open the dialog.
I am pasting here the working code for me.
XAML
<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
<Button Content="Show Dialog" Click="btnShowDialog_Click" />
<callisto:CustomDialog
x:FieldModifier="public"
x:Name="suggestEventDialog"
Title="Suggest an Event"
Background="Teal"
BackButtonVisibility="Visible"
BackButtonClicked="suggestEventDialog_BackButtonClicked_1">
<StackPanel>
<TextBlock
Margin="0,0,0,8"
Text="Suggest an event that should be added to Heron."
FontSize="14.6667"
FontWeight="SemiLight"
TextWrapping="Wrap" />
<TextBlock
Margin="0,0,0,8"
FontSize="14.6667"
FontWeight="SemiLight"
Text="Event URL" />
<callisto:WatermarkTextBox
HorizontalAlignment="Left"
Watermark="http://www.example.com"
Width="400"
Height="35" />
<StackPanel
Margin="0,20,0,0"
HorizontalAlignment="Right"
Orientation="Horizontal">
<Button Content="OK" Width="90" Margin="0,0,20,0" />
<Button Content="CANCEL" Width="90" />
</StackPanel>
</StackPanel>
</callisto:CustomDialog>
</Grid>
C#
private void btnShowDialog_Click(object sender, RoutedEventArgs e)
{
suggestEventDialog.IsOpen = true;
}
private void suggestEventDialog_BackButtonClicked_1(object sender, RoutedEventArgs e)
{
suggestEventDialog.IsOpen = false;
}

Related

How can I make a layout that looks like what I want?

I am working on WinUI3 and the code below shows the image.
<ScrollViewer HorizontalScrollBarVisibility="Auto">
<ItemsRepeater ItemsSource="{x:Bind ViewModel.Collection}">
<ItemsRepeater.ItemTemplate>
<DataTemplate x:DataType="models:Stock">
<Border BorderBrush="Red" BorderThickness="1">
<StackPanel>
<Button Content="{x:Bind Code}" Margin="5"/>
<Button Content="{x:Bind Code}" Margin="5"/>
<Button Content="{x:Bind Code}" Margin="5"/>
</StackPanel>
</Border>
</DataTemplate>
</ItemsRepeater.ItemTemplate>
<ItemsRepeater.Layout>
<UniformGridLayout MaximumRowsOrColumns="2" Orientation="Vertical"/>
</ItemsRepeater.Layout>
</ItemsRepeater>
</ScrollViewer>
result
But what I want is that the height of the item changes as the size of the ScrollViewer changes.
The width of the item has a fixed value, but I want the height to be changed like Stretch of VerticalAlignment.
what i want
How can I make it?
You can do it by setting the UniformGridLayout's MinItemHeight when the ScrollViewer size is changed.
<ScrollViewer
HorizontalScrollBarVisibility="Auto"
SizeChanged="ScrollViewerControl_SizeChanged">
<ItemsRepeater ItemsSource="{x:Bind ViewModel.Collection}">
<ItemsRepeater.ItemTemplate>
<DataTemplate x:DataType="models:Stock">
<Border
BorderBrush="Red"
BorderThickness="1">
<StackPanel>
<Button
Margin="5"
Content="{x:Bind Code}" />
<Button
Margin="5"
Content="{x:Bind Code}" />
<Button
Margin="5"
Content="{x:Bind Code}" />
</StackPanel>
</Border>
</DataTemplate>
</ItemsRepeater.ItemTemplate>
<ItemsRepeater.Layout>
<UniformGridLayout
x:Name="ItemsRepeaterUniformGridLayout"
MaximumRowsOrColumns="2"
Orientation="Vertical" />
</ItemsRepeater.Layout>
</ItemsRepeater>
</ScrollViewer>
private void ScrollViewerControl_SizeChanged(object sender, SizeChangedEventArgs e)
{
int maximumRowsOrColumns = this.ItemsRepeaterUniformGridLayout.MaximumRowsOrColumns;
if (maximumRowsOrColumns > 0)
{
this.ItemsRepeaterUniformGridLayout.MinItemHeight = e.NewSize.Height / maximumRowsOrColumns;
}
}

UWP include/require XAML as in PHP

So I've been struggeling with this really badly and I don't understant any of the found "answers"... I have a menu which I want to use on multiple pages, but not all of them. So I have an "index" page with a splitview in it, to have a menu on the side and the content on the right. But I want to be able to "include" the menu, to be able to edit just one file and not to write in every page the menu again... Below you can find my code of one page;
<Page
x:Class="RittensportRekenSoftware.Views.Index"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:RittensportRekenSoftware.Views"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" RequestedTheme="Dark">
<SplitView x:Name="MySplitView" DisplayMode="CompactOverlay" IsPaneOpen="False" CompactPaneLength="50" OpenPaneLength="150">
<SplitView.Pane>
<!-- Here will the menu be included, so we don't have to re-render it every time again and it's changeable from withing one file -->
<StackPanel Background="#202225" RequestedTheme="Dark">
<Button x:Name="HamburgerButton" FontFamily="Segoe MDL2 Assets" Content="" Width="50" Height="50" Background="Transparent"/>
<StackPanel Orientation="Horizontal">
<Button x:Name="MenuButton1" FontFamily="Segoe MDL2 Assets" Content=""
Width="50" Height="50" Background="Transparent"/>
<TextBlock Text="Button 1" FontSize="18" VerticalAlignment="Center" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Button x:Name="MenuButton2" FontFamily="Segoe MDL2 Assets" Content=""
Width="50" Height="50" Background="Transparent"/>
<TextBlock Text="Button 2" FontSize="18" VerticalAlignment="Center" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Button x:Name="MenuButton3" FontFamily="Segoe MDL2 Assets" Content=""
Width="50" Height="50" Background="Transparent"/>
<TextBlock Text="Button 3" FontSize="18" VerticalAlignment="Center" />
</StackPanel>
</StackPanel>
</SplitView.Pane>
<SplitView.Content>
<Grid>
<TextBlock Text="Content here :D" FontSize="54" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</SplitView.Content>
</SplitView>
</Page>
Now, It would be great to have something like "include menu" that gets the content from a file in Views.Layouts.Menu.xaml, except I have no idea how such file should be made and how to include.
Kindest regards
Robin
Now, It would be great to have something like "include menu" that gets the content from a file in Views.Layouts.Menu.xaml, except I have no idea how such file should be made and how to include.
Making a UserControl was on the right dirction. Please follow my following step to have a try:
Right click your project - Add - New Item - Select User Control
Copy your code into this UserControl XAML page like the following:
<UserControl
x:Class="AppSplit.MyUserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:AppSplit"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400">
<SplitView x:Name="MySplitView" DisplayMode="CompactOverlay" IsPaneOpen="False" CompactPaneLength="50" OpenPaneLength="150">
<SplitView.Pane>
<!-- Here will the menu be included, so we don't have to re-render it every time again and it's changeable from withing one file -->
<StackPanel Background="#202225" RequestedTheme="Dark">
<Button x:Name="HamburgerButton" FontFamily="Segoe MDL2 Assets" Content="" Width="50" Height="50" Background="Transparent" Click="HamburgerButton_Click"/>
<StackPanel Orientation="Horizontal">
<Button x:Name="MenuButton1" FontFamily="Segoe MDL2 Assets" Content=""
Width="50" Height="50" Background="Transparent"/>
<TextBlock Text="Button 1" FontSize="18" VerticalAlignment="Center" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Button x:Name="MenuButton2" FontFamily="Segoe MDL2 Assets" Content=""
Width="50" Height="50" Background="Transparent"/>
<TextBlock Text="Button 2" FontSize="18" VerticalAlignment="Center" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Button x:Name="MenuButton3" FontFamily="Segoe MDL2 Assets" Content=""
Width="50" Height="50" Background="Transparent"/>
<TextBlock Text="Button 3" FontSize="18" VerticalAlignment="Center" />
</StackPanel>
</StackPanel>
</SplitView.Pane>
<SplitView.Content>
<Grid>
<TextBlock Text="Content here :D" FontSize="54" Foreground="Black" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</SplitView.Content>
</SplitView>
</UserControl>
public sealed partial class MyUserControl1 : UserControl
{
public MyUserControl1()
{
this.InitializeComponent();
}
private void HamburgerButton_Click(object sender, RoutedEventArgs e)
{
MySplitView.IsPaneOpen = MySplitView.IsPaneOpen == true ? false : true;
}
}
If you want to include this UserControl on other XAML pages, you could do like the following:
<Page
x:Class="AppSplit.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:AppSplit"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<local:MyUserControl1></local:MyUserControl1>
</Page>

Binding one listview to multiple xaml

How to show one listview to multiple xaml?
on mainpage.xaml, i just want to show binding "Kata". another xaml i want to show binding "Kata" and "Description".
this mainpage.xaml
<ListView x:Name="listView" ItemsSource="{Binding}" HorizontalAlignment="Left" Height="520" VerticalAlignment="Top" Width="340" Margin="10,10,0,0" Grid.Row="2" Background="#33FFFFFF">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Kata}" Tapped="TextBlock_Tapped_1" FontSize="26.667" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
this another xaml.
<ListView x:Name="dictionary_list" ItemsSource="{Binding}" HorizontalAlignment="Left" Height="620" VerticalAlignment="Top" Width="340" Margin="10,10,0,0" Background="{ThemeResource AppBarItemDisabledForegroundThemeBrush}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Kata}" FontSize="26.667" Foreground="White" TextAlignment="Center" />
<TextBlock Text="{Binding Description}" Foreground="White" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Use UserControl and one DependencyProperty whether to show or not description field
ListViewUserContrl.xaml
<UserControl
x:Class="Listview.ListViewUserContrl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Listview"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
d:DesignHeight="300"
d:DesignWidth="400"
x:Name="ListViewUserControl">
<Grid>
<ListView x:Name="dictionary_list" ItemsSource="{Binding}" HorizontalAlignment="Left" Height="620" VerticalAlignment="Top" Width="340" Margin="10,10,0,0" Background="{ThemeResource AppBarItemDisabledForegroundThemeBrush}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="{Binding Kata}" FontSize="26.667" Foreground="White" TextAlignment="Center" />
<TextBlock Text="{Binding Description}" Visibility="{Binding ElementName=ListViewUserControl,Path=DescriptionVisibility}" Foreground="White" />
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</UserControl>
ListViewUserContrl.xaml.cs
public sealed partial class ListViewUserContrl : UserControl
{
public static readonly DependencyProperty DescriptionVisibilityProperty =
DependencyProperty.Register("DescriptionVisibility", typeof(Visibility), typeof(ListViewUserContrl),
new PropertyMetadata(Visibility.Collapsed));
public Visibility DescriptionVisibility
{
get { return (Visibility)GetValue(DescriptionVisibilityProperty); }
set { SetValue(DescriptionVisibilityProperty, value); }
}
public ListViewUserContrl()
{
this.InitializeComponent();
}
}
Add this to your page like this
<local:ListViewUserContrl DescriptionVisibility="Visible"/>

XAML error when using Localized Resources in Context Menu

I have the following code:
<ListBox x:Name="FavList">
<ListBox.ItemTemplate>
<DataTemplate>
<Grid>
<Button x:Name="PlayPause" Style="{StaticResource IconButton}" HorizontalAlignment="Left" Margin="2,2,0,2" Width="72" Click="PlayPause_Click" BorderThickness="0">
<ImageBrush x:Name="PlayPauseImage" ImageSource="Assets\Images\Play.png" />
</Button>
<TextBlock x:Name="myStreamName" Margin="84,8,8,0" TextWrapping="Wrap" Text="{Binding Name, FallbackValue='Test'}" Height="29" VerticalAlignment="Top" FontSize="20" FontWeight="Bold"/>
<TextBlock x:Name="myStreamDescription" Margin="84,37,8,8" TextWrapping="Wrap" Text="{Binding About, FallbackValue='Testing'}" FontSize="16"/>
<TextBlock x:Name="myStreamURL" Text="{Binding URL}" Visibility="Collapsed" />
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu>
<toolkit:MenuItem x:Name="DeleteFavorite" Header="{Binding Path=LocalizedResources.DeleteFavButton, Source={StaticResource LocalizedStrings}}" Click="DeleteFavorite_Click" />
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
</Grid>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
When I have the MenuItem Header equal to what I have there now, I keep getting invalid XAML errors. When I just put in header="Delete" Everything is fine.
Any ideas why this is happening?

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!