|
I want to access some of the public controls in MainWindow from a separate class in the same application domain.
how can I do this?
|
|
|
|
|
Try
Application curApp = Application.Current;<br />
Window mainWnd = curApp.MainWindow;
You can then access public mainWnd objects.
Note: I have not tried this myself.
|
|
|
|
|
Application curApp = Application.Current;
MainWindow mainWnd = curApp.MainWindow;
|
|
|
|
|
I'm working on a SL3 Navigation App in VS2008. By default it created Assets/Styles.xaml. I have been trying to reorganize my xaml resources by moving groups of resources into logically assigned files, and I can't resolve the following issue:
I created a file called "FMBrushesAndColors.XAML", and I was careful to duplicate the property settings that are used by the original "Styles.XAML" fiule.
I then added the file to the App.XAML MergedDictionaries group.
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Assets/FMColorsAndBrushes.xaml"/>
<ResourceDictionary Source="Assets/Styles.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
The problem is that when the app loads, it claims it can't find resources that are defined in that new resource file.
I've also tried creating a MergedDictionaries section in the original Styles.XAML file (and removing the resource line from App.XAML), but I get the same error.
I then tried adding the following code to the app.xaml.cs file, but it throws an InvalidOperationException.
public App()
{
this.Startup += this.Application_Startup;
this.UnhandledException += this.Application_UnhandledException;
AddResourceDictionary("Views/FMColorsAndBrushes.xaml");<br />
InitializeComponent();
}
<br />
private void AddResourceDictionary(string filename)
{
ResourceDictionary dict = new ResourceDictionary();
try
{
dict.Source = new Uri(filename, UriKind.RelativeOrAbsolute);
if (dict != null)
{
this.Resources.MergedDictionaries.Add(dict);
}
}
catch (Exception ex)
{
}
}
Does anyone know the secret to using multiple resource dictionaries in a silverlight app?
SOLUTION =====================================
Alright. I was using some of the resources defined in one dictionary in two other two dictionaries. The rules are as follows (as near as I can determine):
Give dictionaries A, B, and C...
0) If A requires a resource in B, you need to include the following in dictionary A:
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/AssembblyName;component/Assets/B.xaml"/>
</ResourceDictionary.MergedDictionaries>
1) To merge dictionaries A and C, you need to do this in the app.xaml:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Assets/A.xaml"/>
<ResourceDictionary Source="Assets/C.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Notice that you don't have to include B in app.xaml.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
John Simmons / outlaw programmer wrote: this.Resources.MergedDictionaries.Add(dict);
Try Application.Current.Resources.MergedDictionaries.Add(dict); here
|
|
|
|
|
I'm more interested in doing it in the XAML. I only tried that because I wanted to illustrate what I had tried.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Just to make sure - your resources start with the <ResourceDictionary> tag right?
|
|
|
|
|
With what tag?
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
I found the answer (see OP).
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Thanks for posting the solution.
|
|
|
|
|
You could also take back what you said in the Lounge about Silverlight.
|
|
|
|
|
Never.
.45 ACP - because shooting twice is just silly ----- "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001
|
|
|
|
|
Hi All,
I am developing a WYSIWYG editor using Silverlight 4.0 RichText box. I am able to insert images in the RichText box editor, but not able to add shapes (Line, Eclipse, Rectangle etc.)
Can anyone provide me a pointer to do so?
Thanks.
____________________________________________________________
rishabhs
|
|
|
|
|
|
What have you tried so far?
Did you try
myrichTextBox.Selection.Insert(container);
where container is an layout control (say, a stackpanel) containing a shape.
|
|
|
|
|
Thanks Abhinav for your reply. I tried inserting a shape using UIControl.
My requirement is to add shapes like rectangle, ellipse with the same functionality (resize, backcolor, shadow etc) as provided by Word or Visio.
I will try the option suggested by you and will let you know.
Thanks.
____________________________________________________________
rishabhs
|
|
|
|
|
hi,
We are showing Video with slides(images) in silverlight .Our images come from amazon server now we want to cache these images before starting Video.
Any suggestion.
|
|
|
|
|
|
Hi,
I am a beginner in WPF and following Sams WPF in 24 hrs. There is an exercise to do a FontViewer application using grid which displays the list of system fonts and let the user choose any font and view the corresponding font applied on a sample text. I tried using a GRIDSPLITTER which is not resizing at all. Here is the code.
<Window x:Class="FontViewerGrid.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="500" Width="600">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="64*" />
<RowDefinition Height="310*" />
<RowDefinition Height="88*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="190.667*" />
<ColumnDefinition Width="387.333*" />
</Grid.ColumnDefinitions>
<Border Grid.ColumnSpan="2"
CornerRadius="6"
BorderThickness="1"
BorderBrush="Gray"
Background="LightGray"
Margin="6 5 6 5">
<TextBlock Text="Select a font from the list below. You can change the text by typing in the region at the bottom."
FontSize="14" TextWrapping="Wrap" VerticalAlignment="Top"/>
</Border>
<ListBox x:Name="FontList"
Grid.Row="1"
Grid.RowSpan="2"
ItemsSource="{x:Static Fonts.SystemFontFamilies}" Margin="6,5,6,5"/>
<GridSplitter Grid.Row="1" Grid.RowSpan="2"
Grid.Column="1"
Width="2"
Background="Gray"
ResizeDirection="Columns"
ResizeBehavior="PreviousAndNext" Margin="0,1,0,5" HorizontalAlignment="Left" />
<TextBox x:Name="SampleText"
Grid.Row="2"
Grid.Column="1"
MinLines="4"
Margin="6 5 6 5"
TextWrapping="Wrap"
ToolTip="Type here to change the preview text">
The quick brown fox jumps over the lazy dog.
</TextBox>
<GridSplitter Grid.Row="1"
Grid.Column="1"
Width="2"
Background="Gray"
ResizeBehavior="PreviousAndNext"
ResizeDirection="Rows"/>
<StackPanel Grid.Row="1"
Grid.Column="1"
Margin="6 5 6 5">
<TextBlock Text="{Binding ElementName=SampleText, Path=Text}"
FontFamily="{Binding ElementName=FontList, Path=SelectedItem}"
FontSize="10"
TextWrapping="Wrap"
Margin="0 0 0 4"/>
<TextBlock Text="{Binding ElementName=SampleText, Path=Text}"
FontFamily="{Binding ElementName=FontList, Path=SelectedItem}"
FontSize="16"
TextWrapping="Wrap"
Margin="0 0 0 4"/>
<TextBlock Text="{Binding ElementName=SampleText, Path=Text}"
FontFamily="{Binding ElementName=FontList, Path=SelectedItem}"
FontSize="24"
TextWrapping="Wrap"
Margin="0 0 0 4"/>
<TextBlock Text="{Binding ElementName=SampleText, Path=Text}"
FontFamily="{Binding ElementName=FontList, Path=SelectedItem}"
FontSize="32"
TextWrapping="Wrap"
Margin="0 0 0 4"/>
</StackPanel>
</Grid>
</Window>
Please help me in spotting the mistake.
Thanks.
|
|
|
|
|
Put the grid splitter inside its own column:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="64*" />
<RowDefinition Height="310*" />
<RowDefinition Height="88*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="190.667*" />
<ColumnDefinition Width="2" />
<ColumnDefinition Width="387.333*" />
</Grid.ColumnDefinitions>
<Border Grid.ColumnSpan="2"
CornerRadius="6"
BorderThickness="1"
BorderBrush="Gray"
Background="LightGray"
Margin="6 5 6 5">
<TextBlock Text="Select a font from the list below. You can change the text by typing in the region at the bottom."
FontSize="14" TextWrapping="Wrap" VerticalAlignment="Top"/>
</Border>
<ListBox x:Name="FontList"
Grid.Row="1"
Grid.RowSpan="2"
ItemsSource="{x:Static Fonts.SystemFontFamilies}" Margin="6,5,6,5"/>
<GridSplitter Grid.Row="1" Grid.RowSpan="2" Grid.Column="1"
Width="2"
Background="Gray"
ResizeDirection="Columns"
ResizeBehavior="PreviousAndNext" Margin="0,1,0,5" HorizontalAlignment="Stretch" />
<TextBox x:Name="SampleText"
Grid.Row="2"
Grid.Column="2"
MinLines="4"
Margin="6 5 6 5"
TextWrapping="Wrap"
ToolTip="Type here to change the preview text">
The quick brown fox jumps over the lazy dog. </TextBox>
<GridSplitter Grid.Row="1"
Grid.Column="1"
Width="2"
Background="Gray"
ResizeBehavior="PreviousAndNext"
ResizeDirection="Rows"/>
<StackPanel Grid.Row="1"
Grid.Column="2"
Margin="6 5 6 5">
<TextBlock Text="{Binding ElementName=SampleText, Path=Text}"
FontFamily="{Binding ElementName=FontList, Path=SelectedItem}"
FontSize="10"
TextWrapping="Wrap"
Margin="0 0 0 4"/>
<TextBlock Text="{Binding ElementName=SampleText, Path=Text}"
FontFamily="{Binding ElementName=FontList, Path=SelectedItem}"
FontSize="16"
TextWrapping="Wrap"
Margin="0 0 0 4"/>
<TextBlock Text="{Binding ElementName=SampleText, Path=Text}"
FontFamily="{Binding ElementName=FontList, Path=SelectedItem}"
FontSize="24"
TextWrapping="Wrap"
Margin="0 0 0 4"/>
<TextBlock Text="{Binding ElementName=SampleText, Path=Text}"
FontFamily="{Binding ElementName=FontList, Path=SelectedItem}"
FontSize="32"
TextWrapping="Wrap"
Margin="0 0 0 4"/>
</StackPanel>
</Grid>
|
|
|
|
|
Also, it looks like you had two splitters. I took one out. If you want a splitter for rows too, give that splitter it's own row. This shows just the column splitter:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="64*" />
<RowDefinition Height="310*" />
<RowDefinition Height="88*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="190.667*" />
<ColumnDefinition Width="2" />
<ColumnDefinition Width="387.333*" />
</Grid.ColumnDefinitions>
<Border Grid.ColumnSpan="2"
CornerRadius="6"
BorderThickness="1"
BorderBrush="Gray"
Background="LightGray"
Margin="6 5 6 5">
<TextBlock Text="Select a font from the list below. You can change the text by typing in the region at the bottom."
FontSize="14" TextWrapping="Wrap" VerticalAlignment="Top"/>
</Border>
<ListBox x:Name="FontList"
Grid.Row="1"
Grid.RowSpan="2"
ItemsSource="{x:Static Fonts.SystemFontFamilies}" Margin="6,5,6,5"/>
<TextBox x:Name="SampleText"
Grid.Row="2"
Grid.Column="2"
MinLines="4"
Margin="6 5 6 5"
TextWrapping="Wrap"
ToolTip="Type here to change the preview text">
The quick brown fox jumps over the lazy dog. </TextBox>
<GridSplitter Grid.Row="1"
Grid.Column="1"
Grid.RowSpan="2"
Width="2"
Background="Gray"
ResizeBehavior="PreviousAndNext"
ResizeDirection="Columns"/>
<StackPanel Grid.Row="1"
Grid.Column="2"
Margin="6 5 6 5">
<TextBlock Text="{Binding ElementName=SampleText, Path=Text}"
FontFamily="{Binding ElementName=FontList, Path=SelectedItem}"
FontSize="10"
TextWrapping="Wrap"
Margin="0 0 0 4"/>
<TextBlock Text="{Binding ElementName=SampleText, Path=Text}"
FontFamily="{Binding ElementName=FontList, Path=SelectedItem}"
FontSize="16"
TextWrapping="Wrap"
Margin="0 0 0 4"/>
<TextBlock Text="{Binding ElementName=SampleText, Path=Text}"
FontFamily="{Binding ElementName=FontList, Path=SelectedItem}"
FontSize="24"
TextWrapping="Wrap"
Margin="0 0 0 4"/>
<TextBlock Text="{Binding ElementName=SampleText, Path=Text}"
FontFamily="{Binding ElementName=FontList, Path=SelectedItem}"
FontSize="32"
TextWrapping="Wrap"
Margin="0 0 0 4"/>
</StackPanel>
</Grid>
|
|
|
|
|
Got it. Thank you very much
|
|
|
|
|
I'm working with an established and growing commercial software development firm in Philadelphia. They are in need of a very strong C# WPF developer to join their Windows product development team. Agile/ TDD environment. Client is open to contract or full time. The position would be on-site in Philly. If you are interested in more info, I can be reached at ben.cadbury@modis.com. Thanks!
|
|
|
|
|
Please use the jobs forum.
It's time for a new signature.
|
|
|
|
|
Hello,
I want to have a Grid with zero "width" (alas you can't see it) being resized as an effect when I click enter in my program. (Kind of like this: http://www.bestbefore.ro[^] --> click on one of the links and see how the "lines" resize)
However, I have no clue as how to do it. No sample code whatsoever. I would like it to be done via code, or atleast be able to start the effect through code.
Here is my project and source code: http://www.sendspace.com/file/k2vus0[^]
I realize it's a kind of lame project name, but it's a school task. (And I'm not used to WPF, so the "I'm the expert" doesn't really apply :P)
Thanks,
Theo
|
|
|
|