|
How can i dynamically add images in wpf ? i suppose it should be simple , but i just can't find the answer..
Thank you !
|
|
|
|
|
Image myImage = new Image();
myImage.Width = 200;
BitmapImage myBitmapImage = new BitmapImage();
myBitmapImage.BeginInit();
myBitmapImage.UriSource = new Uri(@"C:\Documents and Settings\All Users\Documents\My Pictures\Sample Pictures\Water Lilies.jpg");
myBitmapImage.DecodePixelWidth = 200;
myBitmapImage.EndInit();
myImage.Source = myBitmapImage;
From here[^]
You would then add myImage to the container where you want to show it.
|
|
|
|
|
Hello,
I am trying to trap the click event for a button that is in the resourcedictionary,
I get a error
WpfApplication1.MyResourceDictionary' does not contain a definition for 'GetTemplateChild' and no extension method 'GetTemplateChild' accepting a first argument of type 'WpfApplication1.MyResourceDictionary' could be found (are you missing a using directive or an assembly reference?)
MyResourceDictionay.xaml.cs looks like this
namespace WindowsApplication1
{
partial class MyResourceDictionary
{
public virtual void OnApplyTemplate()
{
Button myButton = this.GetTemplateChild("Crap") as Button;
}
}
}
MyResourceDictionay.xaml looks like this
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="MyResourceDictionary"
x:ClassModifier="public">
<ControlTemplate x:Key="ExpandablePropertyEditorTemplate">
<Button x:Name="Crap" Foreground="White" Background="White">
<Image Source="Controls\check.png"/>
</Button>
</ControlTemplate>
</ResourceDictionary>
Any help?
|
|
|
|
|
|
Hello,
it is possible to make something like a MDI-Application in WPF? Or run a process and get the WPF-Controls of the main window in a control?
I want to make a "plug-in-based" application, and it shouldn't everytime show a new window, i want to have them in my main-application. How is something to do?
|
|
|
|
|
You could have each one open in a new tab. While it is possible to write MDI in WPF, it's a nasty hack because WPF wasn't designed this way.
|
|
|
|
|
Yes in a tab is ok, but how can i do this?
|
|
|
|
|
You'd create these "applications" as plug-ins that your application would use. Have a look at the Managed Extensibility Framework to get some ideas.
|
|
|
|
|
Good People,
I have an object that will hold data and bind to some controls. Sometimes it will just need to exist as one object, other times it will need to exist in a collection. In your opinion, what strategy should/can I use:
1) implement INotifyPropertyChanged on the object, and when needed, place it in the observable collection.
2) simply implement the object normally - without INotifyPropertyChanged - and then place it in the observable collection which will update any properties
By the way, is it possible to use INotifyPropertyChanged and place such objects in an ObservableCollection?
Thank's so much for any help or information you can provide.
Blitz
|
|
|
|
|
Use strategy 1. The ObservableCollection tells you when the collection has changed not when a property of an object inside it has changed.
|
|
|
|
|
Awesome! Thanks Pete. Appreciate you sharing your insight.
|
|
|
|
|
No problem mate. Always glad to help.
|
|
|
|
|
I want to set the default styling in some controls and want to set all properties in generic.xaml.
I am looking at folowing link
http://www.codeproject.com/KB/silverlight/mediabutton.aspx[^]
but if change some property for example
<Setter property="Cursor" Value="Arrow" />
to
<Setter property="Cursor" Value="Hand" />
Its not getting reflected when I run the application.
No idea why? Does anybody have any idea? I have done a lot of brainstorming but not able to find........
Thanks in advance,
|
|
|
|
|
In the constructor for the control(s), try adding
DefaultStyleKey = typeof(MyCustomControlClass);
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have done that also but not able to achieve to get the default value....
|
|
|
|
|
What does the style look like? Can you show the code?
It can't have a Name/Key and it needs to have the correct TargetType.
The Build Action property for the generic.xaml file should be set to resource.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
My CS file is like this:
using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
namespace MyCustomControls
{
public class MyControl: ContentControl
{
public string Content1
{
get { return (string)GetValue(ContentProperty1); }
set { SetValue(ContentProperty1, value); }
}
public static readonly DependencyProperty ContentProperty1 =
DependencyProperty.RegisterAttached("Content", typeof(string), typeof(MyControl),
new PropertyMetadata("a"));
public MyControl()
{
this.DefaultStyleKey = typeof(MyControl);
}
}
}
Generic.xaml
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyCustomControls;assembly=MyCustomControls">
<Style TargetType="local:MyControl">
<Setter Property="VerticalAlignment" Value="Bottom"/>
<Setter Property="HorizontalAlignment" Value="Right"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="VerticalAlignment" Value="Bottom"/>
<Setter Property="Content" Value="The Code Project"/>
</ResourceDictionary>
and the xaml file of the user control where I want to use the above custom control
<UserControl x:Class="MyPortal.Controls.ctrlLogin"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="140"
xmlns:local="clr-namespace:MyCustomControls;assembly=MyCustomControls">
<Grid x:Name="LayoutRoot" Width="400" Height="500" Background="Gray" HorizontalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition Height="480"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="400" />
</Grid.ColumnDefinitions>
<local:MyControl Grid.Column="0" Grid.Row="0"/>
</Grid>
</UserControl>
None of the default property which is there in the generic.xaml file is reflected in the custom control.
If we put this property in the xaml file of user control itself then it works fine. But our requirement is to put the default value having styles or the content in generic.xaml
|
|
|
|
|
You didn't post a complete style example, so it's hard to guess what's wrong.
Here's an example that works for me:
<Style TargetType="local:MyControl">
<Setter Property="VerticalAlignment" Value="Bottom"/>
<Setter Property="HorizontalAlignment" Value="Right"/>
<Setter Property="VerticalAlignment" Value="Bottom"/>
<Setter Property="Foreground" Value="#FF0000FF"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="FontStyle" Value="Italic"/>
<Setter Property="Cursor" Value="Hand"/>
<Setter Property="Content" Value="The Code Project"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:MyControl">
<TextBlock Text="{TemplateBinding Content}"
Cursor="{TemplateBinding Cursor}"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
VerticalAlignment="{TemplateBinding VerticalAlignment}"
FontFamily="{TemplateBinding FontFamily}"
FontSize="{TemplateBinding FontSize}"
FontWeight="{TemplateBinding FontWeight}"
FontStyle="{TemplateBinding FontStyle}"
FontStretch="{TemplateBinding FontStretch}"
Foreground="{TemplateBinding Foreground}"
Margin="{TemplateBinding Padding}" />
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Thanks for ur kind support. The problem is solved....
|
|
|
|
|
As a point of courtesy, you should include how you solved the problem for future readers.
|
|
|
|
|
Hi Derek,
I have solved this problem with the above code given by Mark...
|
|
|
|
|
I’ve just started to build the UI for a quite big WPF-application, and the skeleton of the program will be built with tabs to separate each section of the program. So my question is: what is a proper way to manage all the code inside the TabItem-tags? There will be a lot of UI-code inside the tags (and a lot of code behind as well) so I’m wondering if I can build the UI and the code behind for each TabItem in a separate file and then include the file inside the TabItems?
I’ve been thinking a lot about WPF-pages, but I don’t know how to load them inside a TabItem (I don't even know if it's possibel). But that’s just me thinking, what’s your opinions?
My main file will look something like this:
<StackPanel>
<TabControl TabStripPlacement="Top">
<TabItem Header="Tab1" IsSelected="True">
<!-- Include Tab1 info -->
</TabItem>
<TabItem Header="Tab2">
<!-- Include Tab2 info-->
</TabItem>
<TabItem Header="Tab3">
<!-- Include Tab3 info -->
</TabItem>
</TabControl>
</StackPanel>
Thanks!
// Fredrik
|
|
|
|
|
I'm not sure about pages, but UserControls should work. If you are going to have several tabs that all have significant logic, I would recommend doing that to make it easier to manage.
|
|
|
|
|
Can we use ASP.NET website inside the Silverlight application?
|
|
|
|
|
salon wrote: Can we use ASP.NET website inside the Silverlight application?
No. Why do you want to use ASP.NET website inside Silverlight?
|
|
|
|