WPF: multiuser scheduler - c#

I realize Outlook's like scheduler. I took as the basis: http://www.codeproject.com/Articles/30881/Creating-an-Outlook-Calendar-Using-WPF-Part-2 , but my calendar should have some columns for show data by some count of users. Ofcourse, I can add some user's columns by XAML, but this is static solution and I don't know how many user's will show by my program.
How to improve this program for add dynamic count of user or may be there is some other open source WPF-control's for it?
XAML's code of Calendar style, which create 3 static column in the next:
<Style TargetType="{x:Type local:Calendar}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type local:Calendar}">
<Border Background="#E3EFFF"
BorderBrush="#6593CF"
BorderThickness="2,2,2,2">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="38" />
<RowDefinition Height="22" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<StackPanel Orientation="Horizontal" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Margin="5,0,0,0">
<Button Content="ToPreviousDay" Height="25" Command="{x:Static local:Calendar.PreviousDay}" Background="{x:Null}" BorderBrush="{x:Null}">
</Button>
<Button Content="ToNextDay" Height="25" Command="{x:Static local:Calendar.NextDay}" Background="{x:Null}" BorderBrush="{x:Null}">
</Button>
</StackPanel>
<Border BorderBrush="#6593CF" BorderThickness="0,0,1,1" Grid.Column="0" Grid.Row="1" />
<local:CalendarDayHeader Grid.Column="1" Grid.Row="1" x:Name="PART_DayHeader"/>
<ScrollViewer Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="2" ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Visible" x:Name="PART_ScrollViewer">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<local:CalendarLedger Grid.Column="0" x:Name="PART_Ledger" Margin="0,25,0,0"/>
<StackPanel Orientation="Horizontal" Grid.Column="1">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label Grid.Row="0" Content="User1_Column" x:Name="PART_Label"/>
<local:CalendarDay Grid.Row="1" x:Name="PART_Day" />
</Grid>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label Grid.Row="0" Content="User2_Column" x:Name="PART_Label2"/>
<local:CalendarDay Grid.Row="1" x:Name="PART_Day2" />
</Grid>
<Grid Width>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Label Grid.Row="0" Content="User3_Column" x:Name="PART_Label3"/>
<local:CalendarDay Grid.Row="1" x:Name="PART_Day3" />
</Grid>
</StackPanel>
</Grid>
</ScrollViewer>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I want to add user's columns dynamically

Related

WPF - Infinite datagrid height

I am using Syncfusion's SfDataGrid instead of standard one, but this question is more about XAML, not the control itself, I think.
So, I have a window with DataGrid. If there is for example 60 records, then the window gets really tall. I want the window not to change its size at all. And really don't know why it's happening.
This is my XAML:
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Margin="10,0,10,0" Grid.Row="0" DataContext="{Binding Info}">
<TextBlock Text="Amount:"/>
<sf:CurrencyTextBox Value="{Binding Amount}" Margin="0,0,0,10"/>
<!-- some other controls -->
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Grid.Row="0" Style="{StaticResource LeftLabel}"
Text="Count:"/>
<sf:UpDown Grid.Column="1" Grid.Row="0" Margin="0,0,0,5"
Value="{Binding Count}"/>
<TextBlock Grid.Column="0" Grid.Row="1" Style="{StaticResource LeftLabel}"
Text="Year count:"/>
<sf:UpDown Grid.Column="1" Grid.Row="1"
Value="{Binding YearCount}"/>
</Grid>
</StackPanel>
<Button Grid.Row="1" HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="0,10,10,5"
Content="Simulate >>"
Command="{Binding SimulateCommand}"/>
</Grid>
<!-- This is right part of the window with datagrid -->
<DockPanel Grid.Column="1">
<WrapPanel DockPanel.Dock="Top">
<TextBlock Margin="10" Text="Total amount:" />
<TextBlock Text="{Binding TotalAmount"/>
</WrapPanel>
<!-- and the datagrid -->
<sf:SfDataGrid AutoGenerateColumns="False"
AllowDeleting="False"
AllowEditing="False"
IsReadOnly="False"
AllowGrouping="False"
AllowFiltering="False"
ItemsSource="{Binding History}">
<sf:SfDataGrid.Columns>
<sf:GridDateTimeColumn DisplayBinding="{Binding Date}" MappingName="PaymentDay" HeaderText="Date"/>
<sf:GridCurrencyColumn DisplayBinding="{Binding Amount}" MappingName="PayAmount" HeaderText="Amount"/>
</sf:SfDataGrid.Columns>
</sf:SfDataGrid>
</DockPanel>
</Grid>
So what is wrong with it?

PopUp control does not move with the Window, while moving the window after we resize it

I am facing one issue with the WPF popup control.
When we resize the window and move it, PopUp control remains at same position at which it was open previously and does not move with the window.
So what is the solution for this issue.
please provide code snippet for the solution if any. Thanks :)
Xaml code for popup control is as follows:
<Popup x:Name="popNonTopMostPopup" Height="200" Width="220" AllowsTransparency="True" Placement="Right">
<Grid Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<fa:FontAwesome Grid.Column="0" Icon="Play" FontSize="30" HorizontalAlignment="Right" Rotation="180" VerticalAlignment="Top" Margin="0 7 -2 0" />
<Border Grid.Column="1" BorderBrush="LightGray" Background="Black" CornerRadius="5" Height="200" Width="200">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Button x:Name="btnCustomPopup" Click="btnCustomPopup_Click" HorizontalAlignment="Right" Background="Transparent" Foreground="LightGray" BorderBrush="Transparent" Grid.Row="0">
<StackPanel Margin="0">
<fa:FontAwesome Icon="Close" VerticalAlignment="Center" />
</StackPanel>
</Button>
<Label x:Name="lblName" Grid.Row="1" Foreground="LightGray"/>
<Grid Grid.Row="2">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label x:Name="lblDueDate" Foreground="LightGray" Content="Fristdatum: " Grid.Column="0" VerticalAlignment="Bottom" Visibility="Hidden"></Label>
<TextBlock x:Name="txtDueDate" Foreground="LightGray" HorizontalAlignment="Left" Grid.Column="1" VerticalAlignment="Center" Visibility="Hidden"></TextBlock>
</Grid>
<Separator Grid.Row="3"></Separator>
<TextBlock x:Name="txtComments" Foreground="LightGray" TextWrapping="WrapWithOverflow" Grid.Row="4" Margin="10 10 10 10"></TextBlock>
</Grid>
</Border>
</Grid>
</Popup>
We have icons on map on click of which pop up control is displayed.Code for click event is as follows.
void pin_MouseLeftButtonDownForOrder(object sender, MouseButtonEventArgs e)
{
// set the placement target of popup as pin mapicon
popNonTopMostPopup.PlacementTarget = orderIcon;
popNonTopMostPopup.IsOpen = true;
}

Responsive UI for WPF applications

I have been trying to adjust the screen based on different sizes to see if any components are reacting to that. Unfortunately they don't
I am not sure what I am missing. And it would be great if anyone can give a direct advice and tips for my example implementation.
Here is the code:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="1000" Width="800">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ListView Grid.Column="0" Grid.RowSpan="3" Grid.ColumnSpan="3" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<ListViewItem Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="4" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Expander HorizontalAlignment="Stretch" Grid.Column="0" Grid.Row="1" VerticalAlignment="Stretch">
<Grid Width="Auto" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20" />
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="20*"/>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Grid.Column="1" Grid.Row="0" Content="HJello World meeee"/>
<ListView Grid.Column="3" Grid.Row="0" Grid.RowSpan="4">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"></StackPanel>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<Button Content="Hello Tourist fu"/>
<Button Content="Hello Tourist fu"/>
<Button Content="Hello Tourist fu"/>
<Button Content="Hello Tourist fu"/>
<Button Content="Hello Tourist fu"/>
<ListViewItem Content="Test"/>
</ListView>
<Button Grid.Column="4" Grid.Row="0" Content="Test"/>
</Grid>
</Expander>
</Grid>
</ListViewItem>
<ListViewItem Grid.Column="0" Grid.Row="0" Grid.ColumnSpan="4">
<Expander >
<Grid Width="Auto">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="20" />
<ColumnDefinition Width="2*"/>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="20*"/>
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Label Grid.Column="1" Grid.Row="0" Content="HJello World meeee"/>
<ListView Grid.Column="3" Grid.Row="0" Grid.RowSpan="4">
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"></StackPanel>
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<Button Content="Hello Tourist fu"/>
<Button Content="Hello Tourist fu"/>
<Button Content="Hello Tourist fu"/>
<Button Content="Hello Tourist fu"/>
<Button Content="Hello Tourist fu"/>
<ListViewItem Content="Test"/>
</ListView>
<Button Grid.Column="4" Grid.Row="0" Content="Test"/>
</Grid>
</Expander>
</ListViewItem>
</ListView>
</Grid>
</Window>
Set x:Name for your main grid to x:Name="Root"
Set for Expander attribute Width="{Binding ActualWidth, ElementName=Root}"

Tabcontrol in WPF C#

now I'm using the tabcontrol to arrange my UI. At the first, I put my button outside my tabcontrol; however, when I put the button into the tabcontrol, it gave message, Object reference not set to an object instance. Does anyone know why I got this message ?
edited
Below is my xaml:
<Window x:Class="StudySystem.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="UI" Height="600" Width="811" mc:Ignorable="d" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:my="clr-namespace:StudySystem" Loaded="Window_Loaded">
<Grid Width="791">
<Grid.RowDefinitions>
<RowDefinition Height="129*" />
<RowDefinition Height="432*" />
</Grid.RowDefinitions>
<TabControl Margin="2,0,0,42">
<TabItem Header="Book Info" >
<Grid ShowGridLines="False">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="150" />
<ColumnDefinition Width="150" />
<ColumnDefinition Width="178*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="22*" />
</Grid.RowDefinitions>
<TextBlock Text="Book Code:" Height="25" Margin="0,15,0,45"></TextBlock>
<TextBox Name="txtCode" Grid.Column="1" Margin="2,15,0,51"
Width="148"></TextBox>
<TextBlock Grid.Row="1" Text="Title:" Margin="0,1,0,33" Height="18"></TextBlock>
<TextBox Name="txtTitle" Grid.Row="1" Grid.Column="1" Margin="2,1,148,32" Grid.ColumnSpan="2"></TextBox>
<TextBlock Grid.Row="3" Text="Author:" Margin="0,5,0,33" Height="17"></TextBlock>
<TextBox Name="txtAuthor" Grid.Row="3" Grid.Column="1" Margin="0,6,0,30"></TextBox>
<Button Content="OK" Grid.Row="4" Grid.Column="1" Margin="0,1,0,37"></Button>
</Grid>
</TabItem>
</TabControl>
</Grid>
</Window>
I've seen this before, its code that references things in your form before you create the form. Check the order of what you are calling.
Inside Windows tag i have added this code and for me its working fine...
<Grid Width="auto">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="432*" />
</Grid.RowDefinitions>
<TabControl Grid.Row="1">
<TabItem Header="Book Info" >
<Grid ShowGridLines="False">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="150" />
<ColumnDefinition Width="150" />
<ColumnDefinition Width="178*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="22*" />
</Grid.RowDefinitions>
<TextBlock Text="Book Code:" Height="25" Margin="0,15,0,45"> </TextBlock>
<TextBox Name="txtCode" Grid.Column="1" Margin="2,15,0,51"
Width="148"></TextBox>
<TextBlock Grid.Row="1" Text="Title:" Margin="0,1,0,33" Height="18"></TextBlock>
<TextBox Name="txtTitle" Grid.Row="1" Grid.Column="1" Margin="2,1,148,32" Grid.ColumnSpan="2"></TextBox>
<TextBlock Grid.Row="3" Text="Author:" Margin="0,5,0,33" Height="17"></TextBlock>
<TextBox Name="txtAuthor" Grid.Row="3" Grid.Column="1" Margin="0,6,0,30"></TextBox>
<Button Content="OK" Grid.Row="4" Grid.Column="1" Margin="0,1,0,37"></Button>
</Grid>
</TabItem>
</TabControl>
</Grid>
what you have mentioned in window_loaded??

WPF window throws TypeInitializationException at start up

I have an Excel AddIn with several ribbons, one ribbon is setting window.
When it is clicked, a custom window will show up.
However, there is nothing to show up when clicked.
I saw the following exceptions in log file. What causes this and how to fix it? thanks a lot
2012-04-09 09:59:50,161 [1] ERROR Helper [(null)] - Name:TypeInitializationException
Message:The type initializer for 'System.Windows.Window' threw an exception.
Target:Void .ctor()
Stack: at System.Windows.Window..ctor()
at MyShared.View.ConnectionSetup..ctor()
at MyAddIn.Connect.GetSettings()
at MyAddIn.Connect.BtnClick(IRibbonControl control)
Name:TypeInitializationException
Message:The type initializer for 'System.Windows.FrameworkElement' threw an exception.
Target:Void .cctor()
Stack: at System.Windows.Window..cctor()
Name:TypeInitializationException
Message:The type initializer for 'System.Windows.Documents.TextElement' threw an exception.
Target:Void .cctor()
Stack: at System.Windows.FrameworkElement..cctor()
Name:TypeInitializationException
Message:The type initializer for 'MS.Internal.FontCache.Util' threw an exception.
Target:Int32 get_Dpi()
Stack: at MS.Internal.FontCache.Util.get_Dpi()
at System.Windows.SystemFonts.ConvertFontHeight(Int32 height)
at System.Windows.Documents.TextElement..cctor()
Name:UriFormatException
Message:Invalid URI: The format of the URI could not be determined.
Target:Void CreateThis(System.String, Boolean, System.UriKind)
Stack: at System.Uri.CreateThis(String uri, Boolean dontEscape, UriKind uriKind)
at System.Uri..ctor(String uriString, UriKind uriKind)
at MS.Internal.FontCache.Util..cctor()
Edit, here is xaml code
<Window x:Class="MyShared.View.ConnectionSetup"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit"
xmlns:Converter="clr-namespace:MIMICShared.Converter"
WindowStartupLocation="CenterOwner"
Title="Settings" Width="446" Height="650" Closing="WindowClosing"
DataContextChanged="UserControlDataContextChanged" Foreground="Black" FontWeight="Normal" HorizontalAlignment="Stretch">
<Window.Resources>
<ResourceDictionary>
<Converter:Status2ImageConverter x:Key="string2Image"/>
</ResourceDictionary>
</Window.Resources>
<Grid FocusManager.FocusedElement="{Binding ElementName=uname}" >
<Grid.RowDefinitions>
<RowDefinition Height="0"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="0"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="0"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="5"></RowDefinition>
</Grid.RowDefinitions>
<GroupBox Grid.Row="1" Foreground="Blue">
<Grid >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="5"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="5"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="2"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="2"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="2"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="2"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="2"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="2"></RowDefinition>
</Grid.RowDefinitions>
<Label Grid.Row="1" Grid.ColumnSpan="4" FontSize="14" HorizontalAlignment="Center" FontWeight="Bold" VerticalAlignment="Bottom">Historical</Label>
<GroupBox Grid.Column="1" Grid.Row="3" Header="Connections" Foreground="Blue" Grid.ColumnSpan="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" ></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<toolkit:DataGrid x:Name="connectionlist" Margin="5" Style="{DynamicResource DataGridStyleDefault}" Background="White"
AutoGenerateColumns="False" HeadersVisibility="All"
SelectionMode="Single"
GridLinesVisibility="None"
ItemsSource="{Binding SettingList}" CanUserAddRows="False" CanUserDeleteRows="True"
SelectionUnit="FullRow" SelectedItem="{Binding SelectedItem}"
SelectionChanged="ConnectionlistSelectionChanged"
VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
<!-- Column definition -->
<toolkit:DataGrid.Columns>
<!-- Pool -->
<!--<toolkit:DataGridCheckBoxColumn Header="Pool" Width="40" Binding="{Binding pool}" />-->
<!-- Connections info -->
<toolkit:DataGridTextColumn Header="Connection Info" Width="*" Binding="{Binding host}" />
<toolkit:DataGridTextColumn Header="Description" Width="*" Binding="{Binding desc}" >
<toolkit:DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="TextWrapping" Value="Wrap" />
</Style>
</toolkit:DataGridTextColumn.ElementStyle>
</toolkit:DataGridTextColumn>
</toolkit:DataGrid.Columns>
</toolkit:DataGrid>
<Grid Grid.Row="2" HorizontalAlignment="Center">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Button Margin="2" Padding="10 0" x:Name="AddButton" Click="AddClicked">Add</Button>
<Button Grid.Column="1" Margin="2" Padding="10 0" Command="{Binding Remove}">Remove</Button>
</Grid>
</Grid>
</Grid>
</GroupBox>
<GroupBox Header="Authentication" Grid.Row="5" Grid.Column="1" Foreground="Blue" Grid.ColumnSpan="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="2"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="2"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="5"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0">Username:</Label>
<TextBox x:Name="uname" Width="100" Grid.Row="0" Grid.Column="2" Text="{Binding UserName, UpdateSourceTrigger=PropertyChanged}" ></TextBox>
<Label Grid.Row="2" Grid.Column="0">Password:</Label>
<PasswordBox x:Name="pwd" ToolTip="Password" PasswordChar="*"
Width="100" Grid.Row="2" Grid.Column="2" KeyDown="OnKeyDownHandler"></PasswordBox>
<Label Grid.Row="2" Grid.Column="3">
<Hyperlink Click="HyperlinkClick">Forgot Password?</Hyperlink>
</Label>
<CheckBox Margin="10 0 0 0" Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" x:Name="saveauth" IsChecked="{Binding SaveAuth}">Save username and password</CheckBox>
<Button Margin="10 0 0 0" Grid.Row="4" Grid.Column="3" Click="VerifyButtonClick">OK</Button>
</Grid>
</GroupBox>
<GroupBox Header="Status" Grid.Row="7" Grid.Column="1" Foreground="Blue" Grid.ColumnSpan="2">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="0"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="0"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80"/>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="1" Grid.Column="0">Historical</Label>
<Image Grid.Row="1" Grid.Column="1"
Source="{Binding ElementName=historicalStatusLabel, Path=Content, Converter={StaticResource string2Image}}"
ToolTip="Connection Status"></Image>
<Label Name="historicalStatusLabel" Grid.Row="1" Grid.Column="2" Content="{Binding ConnectionStatus, UpdateSourceTrigger=PropertyChanged}"/>
</Grid>
</GroupBox>
</Grid>
</GroupBox>
<GroupBox Grid.Row="3" Grid.Column="1" Foreground="Blue">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="0"></RowDefinition>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="0"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="0"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="0"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="0"></RowDefinition>
</Grid.RowDefinitions>
<Label Grid.Row="1" FontSize="14" FontWeight="Bold" HorizontalAlignment="Center" VerticalAlignment="Bottom">Real Time</Label>
<GroupBox Header="Authorization" Grid.Row="3" Grid.Column="1" Foreground="Blue">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="2"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="2"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="2"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0">Username:</Label>
<TextBox x:Name="RTDemail" Width="100" Grid.Row="0" Grid.Column="2" Text="{Binding RTDUserName, UpdateSourceTrigger=PropertyChanged}"></TextBox>
<Label Grid.Row="2" Grid.Column="0">Password:</Label>
<PasswordBox x:Name="RTDpwd" ToolTip="Password" PasswordChar="*"
Width="100" Grid.Row="2" Grid.Column="2" KeyDown="OnKeyDownHandler"></PasswordBox>
<Label Grid.Row="2" Grid.Column="3">
<Hyperlink Click="HyperlinkClickRTD">Forgot Password?</Hyperlink>
</Label>
<CheckBox Margin="10 0 0 0" Grid.Row="4" Grid.Column="0" Grid.ColumnSpan="2" x:Name="RTDsaveauth" IsChecked="{Binding RTDSaveAuth}">Save username and password</CheckBox>
<Button Margin="10 0 0 0" Grid.Row="4" Grid.Column="3" Click="RTDVerifyButtonClick">OK</Button>
</Grid>
</GroupBox>
<GroupBox Grid.Row="5" Grid.ColumnSpan="3">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="10"></ColumnDefinition>
<ColumnDefinition Width="Auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Label Grid.Column="1" Margin="0 0 0 0" Foreground="Blue">Server</Label>
<Label Name="RTDServerURLLabel" Grid.Column="2" Content="{Binding RTDServerURL}"></Label>
</Grid>
</GroupBox>
<GroupBox Header="Status" Grid.Row="7" Grid.Column="1" Foreground="Blue">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="2"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="2"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80"/>
<ColumnDefinition Width="20"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Label Grid.Row ="1" Grid.Column="0">Real Time</Label>
<Image Grid.Row ="1" Grid.Column="1"
Source="{Binding ElementName=RTDStatusLabel, Path=Content, Converter={StaticResource string2Image}}"
ToolTip="Connection Status" HorizontalAlignment="Left" Width="20"></Image>
<Label Name="RTDStatusLabel" Grid.Row="1" Grid.Column="2" Content="{Binding RTDConnectionStatus, UpdateSourceTrigger=PropertyChanged}"></Label>
</Grid>
</GroupBox>
</Grid>
</GroupBox>
<Grid Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="3" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="60"></ColumnDefinition>
<ColumnDefinition Width="20"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Button x:Name="CloseButton" Click="CloseButtonClick" Grid.Column ="1" Margin="0,0,0,0">Close</Button>
</Grid>
</Grid>
When ribbon is clicked, the code is executed, ConnectionSetup is the xaml file above
private bool GetSettings()
{
var settingUI = new ConnectionSetup();
settingUI.DataContext = Settings;
CenterMainWindow(settingUI, wndHandle.Handle);
bool? result = settingUI.ShowDialog();
return result ?? false;
}
private void CenterMainWindow(System.Windows.Window window, IntPtr ownerHandle)
{
var helper = new System.Windows.Interop.WindowInteropHelper(window) {Owner = ownerHandle};
// Center window
// Note - Need to use HwndSource to get handle to WPF owned window,
// and the handle only exists when SourceInitialized has been
// raised
window.SourceInitialized += delegate
{
// Get WPF size and location for non-WPF owner window
var nonWPFOwnerLeft = XLApp.Left;
var nonWPFOwnerWidth = XLApp.Width;
var nonWPFOwnerTop = XLApp.Top;
var nonWPFOwnerHeight = XLApp.Height;
// Get transform matrix to transform non-WPF owner window
// size and location units into device-independent WPF
// size and location units
var source = System.Windows.Interop.HwndSource.FromHwnd(helper.Handle);
if (source != null && source.CompositionTarget != null)
{
var matrix = source.CompositionTarget.TransformFromDevice;
var ownerWPFSize =
matrix.Transform(new System.Windows.Point(nonWPFOwnerWidth,
nonWPFOwnerHeight));
var ownerWPFPosition =
matrix.Transform(new System.Windows.Point(nonWPFOwnerLeft,
nonWPFOwnerTop));
// Center WPF window
window.WindowStartupLocation = WindowStartupLocation.Manual;
window.Left = Math.Max(0,
ownerWPFPosition.X +
(ownerWPFSize.X - window.Width)/2);
window.Top = Math.Max(0,
ownerWPFPosition.Y +
(ownerWPFSize.Y - window.Height)/2);
}
};
}
Judging from the error stack you posted, it appears that your settings window probably has a link on it. Unfortunately, the link has an invalid url in it, which causes the creation of the window to fail.
EDIT:
Having looked more closely at your code and error messages, it's clear that I was looking in the wrong area. Some searching turned up a bug in wpf.
The short version: the windir environment variable may be set incorrectly on the target machine, which causes the font subsytem to break. The workaround is to fix the environment variable, either on the target machine's registry, or in the code by adding something like the following to the startup:
Environment.SetEnvironmentVariable("windir", Environment.GetEnvironmentVariable("SystemRoot"));
We had a couple of people experience this problem. The solution described here (caused by PATH being greater than 2048 characters) resolved the issue.
I am concerned that the statement suggested above may be problematic in code that is running with either too many or too few privileges. Certainly my app running with on my workstation with me as administrator has no issue with this call to
Environment.SetEnvironmentVariable("windir",Environment.GetEnvironmentVariable("SystemRoot"));
but I am not sure that SetEnvironmentVariable will actually work on a locked-down OS. Has anybody a) tried this for real and b) tried it in a low-privilege environment>
Also, I am seeing some oddity on app startup after I install an app with this call, and run it once. All other applications no longer can see windir,which is not expanding to C:\Windows. I am going to go through the whole install and run without it in place and see if either the TypeInvocation exception resurfaces or if not, whether the OS windir variable is left intact.
UPDATE:
I have confirmed that the bad behavior I noticed was due to not specifying the target of the SetEnvironment call. Using the following my problems seem to have been alleviated:
System.Environment.SetEnvironmentVariable("windir", System.Environment.GetEnvironmentVariable("SystemRoot"), EnvironmentVariableTarget.User);
When I did not set the target, very odd things happened to my Windows session requiring me to either logoff and login or even reboot. So unless this change is really to be at the machine or process level, do not assume happy results with the default

Categories

Resources