|
You could either set a new value in the resource dictionary:
Resources["BrushWindowMainBackground"] = (Brush)TryFindResource("MyCoolBreezeGradientBrush");
Or change the brush itself, I don't know if this would work in all situations but it seemed to in this one.
SolidColorBrush b = (SolidColorBrush)TryFindResource("BrushWindowMainBackground");
b.Color = Colors.Green;
Also make sure your using DynamicResource in the xaml and not StaticResource.
|
|
|
|
|
Thanks, I will try that and see what happens.
Also, what do you think about using styles?
|
|
|
|
|
Actually, it worked. By the way, what do the Brackets "[]" mean? What do they do that parentheses would not?
Thanks,
BP
|
|
|
|
|
This is something you need to plan carefully imho.
At work I've spent about a month putting together/organising thousands of lines of styles into a style dll. We are planning on having a few 'skins' that users can choose from. Personally I prefer the idea of offering skins over allowing a user to change individual colours since that can wind up with an horrific mish mash of contrasting rubbish in the UI.
Have a look at this article on CP its where I started along this path and its a seriously cool CP article in general that covers this topic really well.
http://www.codeproject.com/KB/WPF/wpfskins.aspx[^]
|
|
|
|
|
Hey guys.
I'm totally new to WPF and I'm trying to write a control with it. The control is a calender and will be used as a roster where the user will select a shift to use for a specific day and then when one cycle has been set up the user must be able to copy that cycle for the rest of the year for example.
Here is the XAML code i have so far... Sorry if its a bit long
<UserControl x:Class="WPF_Calender_Control.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="350 " Width="420">
<Grid >
<Grid.RowDefinitions>
<RowDefinition Height="25*" Focusable="True" />
<RowDefinition Height="25*" Focusable="True" />
<RowDefinition Height="60*" Focusable="True" />
<RowDefinition Height="60*" Focusable="True" />
<RowDefinition Height="60*" Focusable="True" />
<RowDefinition Height="60*" Focusable="True" />
<RowDefinition Height="60*" Focusable="True" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="60*" />
<ColumnDefinition Width="60*" />
<ColumnDefinition Width="60*" />
<ColumnDefinition Width="60*" />
<ColumnDefinition Width="60*" />
<ColumnDefinition Width="60*" />
<ColumnDefinition Width="60*" />
</Grid.ColumnDefinitions>
<Rectangle Fill="LightGreen" Grid.Column="0" Grid.Row="1"/>
<Rectangle Fill="LightGreen" Grid.Column="1" Grid.Row="1"/>
<Rectangle Fill="LightGreen" Grid.Column="2" Grid.Row="1"/>
<Rectangle Fill="LightGreen" Grid.Column="3" Grid.Row="1"/>
<Rectangle Fill="LightGreen" Grid.Column="4" Grid.Row="1"/>
<Rectangle Fill="LightGreen" Grid.Column="5" Grid.Row="1"/>
<Rectangle Fill="LightGreen" Grid.Column="6" Grid.Row="1"/>
<Border Grid.Column="0" Grid.Row="1" BorderBrush="Black" BorderThickness="1"/>
<Border Grid.Column="1" Grid.Row="1" BorderBrush="Black" BorderThickness="1"/>
<Border Grid.Column="2" Grid.Row="1" BorderBrush="Black" BorderThickness="1"/>
<Border Grid.Column="3" Grid.Row="1" BorderBrush="Black" BorderThickness="1"/>
<Border Grid.Column="4" Grid.Row="1" BorderBrush="Black" BorderThickness="1"/>
<Border Grid.Column="5" Grid.Row="1" BorderBrush="Black" BorderThickness="1"/>
<Border Grid.Column="6" Grid.Row="1" BorderBrush="Black" BorderThickness="1"/>
<Border Grid.Column="0" Grid.Row="2" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="1" Grid.Row="2" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="2" Grid.Row="2" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="3" Grid.Row="2" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="4" Grid.Row="2" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="5" Grid.Row="2" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="6" Grid.Row="2" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="0" Grid.Row="3" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="1" Grid.Row="3" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="2" Grid.Row="3" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="3" Grid.Row="3" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="4" Grid.Row="3" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="5" Grid.Row="3" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="6" Grid.Row="3" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="0" Grid.Row="4" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="1" Grid.Row="4" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="2" Grid.Row="4" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="3" Grid.Row="4" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="4" Grid.Row="4" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="5" Grid.Row="4" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="6" Grid.Row="4" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="0" Grid.Row="5" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="1" Grid.Row="5" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="2" Grid.Row="5" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="3" Grid.Row="5" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="4" Grid.Row="5" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="5" Grid.Row="5" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="6" Grid.Row="5" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="0" Grid.Row="6" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="1" Grid.Row="6" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="2" Grid.Row="6" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="3" Grid.Row="6" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="4" Grid.Row="6" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="5" Grid.Row="6" BorderBrush="Black" BorderThickness="0.5"/>
<Border Grid.Column="6" Grid.Row="6" BorderBrush="Black" BorderThickness="0.5"/>
<Canvas Name="Canvas00" Grid.Column="0" Grid.Row="2"/>
<Canvas Name="Canvas10" Grid.Column="1" Grid.Row="2"/>
<Canvas Name="Canvas20" Grid.Column="2" Grid.Row="2"/>
<Canvas Name="Canvas30" Grid.Column="3" Grid.Row="2"/>
<Canvas Name="Canvas40" Grid.Column="4" Grid.Row="2"/>
<Canvas Name="Canvas50" Grid.Column="5" Grid.Row="2"/>
<Canvas Name="Canvas60" Grid.Column="6" Grid.Row="2"/>
<Canvas Name="Canvas01" Grid.Column="0" Grid.Row="3"/>
<Canvas Name="Canvas11" Grid.Column="1" Grid.Row="3"/>
<Canvas Name="Canvas21" Grid.Column="2" Grid.Row="3"/>
<Canvas Name="Canvas31" Grid.Column="3" Grid.Row="3"/>
<Canvas Name="Canvas41" Grid.Column="4" Grid.Row="3"/>
<Canvas Name="Canvas51" Grid.Column="5" Grid.Row="3"/>
<Canvas Name="Canvas61" Grid.Column="6" Grid.Row="3"/>
<Canvas Name="Canvas02" Grid.Column="0" Grid.Row="4"/>
<Canvas Name="Canvas12" Grid.Column="1" Grid.Row="4"/>
<Canvas Name="Canvas22" Grid.Column="2" Grid.Row="4"/>
<Canvas Name="Canvas32" Grid.Column="3" Grid.Row="4"/>
<Canvas Name="Canvas42" Grid.Column="4" Grid.Row="4"/>
<Canvas Name="Canvas52" Grid.Column="5" Grid.Row="4"/>
<Canvas Name="Canvas62" Grid.Column="6" Grid.Row="4"/>
<Canvas Name="Canvas03" Grid.Column="0" Grid.Row="5"/>
<Canvas Name="Canvas13" Grid.Column="1" Grid.Row="5"/>
<Canvas Name="Canvas23" Grid.Column="2" Grid.Row="5"/>
<Canvas Name="Canvas33" Grid.Column="3" Grid.Row="5"/>
<Canvas Name="Canvas43" Grid.Column="4" Grid.Row="5"/>
<Canvas Name="Canvas53" Grid.Column="5" Grid.Row="5"/>
<Canvas Name="Canvas63" Grid.Column="6" Grid.Row="5"/>
<Canvas Name="Canvas04" Grid.Column="0" Grid.Row="6"/>
<Canvas Name="Canvas14" Grid.Column="1" Grid.Row="6"/>
<Canvas Name="Canvas24" Grid.Column="2" Grid.Row="6"/>
<Canvas Name="Canvas34" Grid.Column="3" Grid.Row="6"/>
<Canvas Name="Canvas44" Grid.Column="4" Grid.Row="6"/>
<Canvas Name="Canvas54" Grid.Column="5" Grid.Row="6"/>
<Canvas Name="Canvas64" Grid.Column="6" Grid.Row="6" />
<Label FontSize="10" HorizontalContentAlignment="Center" Name="label1" VerticalContentAlignment="Center" Grid.Column="0" Grid.Row="1">
Sunday
</Label>
<Label FontSize="10" HorizontalContentAlignment="Center" Name="label2" VerticalContentAlignment="Center" Grid.Column="1" Grid.Row="1">
Monday
</Label>
<Label FontSize="10" HorizontalContentAlignment="Center" Name="label3" VerticalContentAlignment="Center" Grid.Column="2" Grid.Row="1">
Tuesday
</Label>
<Label FontSize="10" HorizontalContentAlignment="Center" Name="label4" VerticalContentAlignment="Center" Grid.Column="3" Grid.Row="1">
Wensday
</Label>
<Label FontSize="10" HorizontalContentAlignment="Center" Name="label5" VerticalContentAlignment="Center" Grid.Column="4" Grid.Row="1">
Thursday
</Label>
<Label FontSize="10" HorizontalContentAlignment="Center" Name="label6" VerticalContentAlignment="Center" Grid.Column="5" Grid.Row="1">
Friday
</Label>
<Label FontSize="10" HorizontalContentAlignment="Center" Name="label7" VerticalContentAlignment="Center" Grid.Column="6" Grid.Row="1">
Saturday
</Label>
<Label FontSize="14" HorizontalContentAlignment="Center" Name="lblMonthYear" VerticalContentAlignment="Center" Grid.ColumnSpan="8" FontFamily="Comic Sans MS" FontWeight="Black">
July 2008
</Label>
<Button Name="btnSubtractYear" Grid.Column="0" Click="btnSubtractYear_Click"><< Year</Button>
<Button Name="btnSubtractMonth" Grid.Column="1" Click="btnSubtractMonth_Click"><< Month</Button>
<Button Name="btnAddMonth" Grid.Column ="5" Click="btnAddMonth_Click">Month >></Button>
<Button Name="btnAddYear" Grid.Column="6" Click="btnAddYear_Click">Year >></Button>
</Grid>
</UserControl>
As you can see ive got "Canvas" objects within the grid, but im not sure if thats the right control for what i need it to do.
at this point i need to be able to some painting on it from the code behind, depending on which month & year is selected the day numbers need to be drawn in the right blocks, but i cant seem to figure out how to do that... my brain is still thinking in GDI
any help would be appreciated
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.passion != Programming)
|
|
|
|
|
WRAP PANEL ALERT!!!!
Have a look into the wrap panel. Also you could:
<Style x:Name="CalCellBorder" TargetType="{x:Type Border}">
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="BorderThickness" Value="0.5" />
<Style>
Then, if the style is placed inside:
<UserControl.Resources>
</UserControl.Resources>
Such As:
<UserControl.Resources>
<Style x:Name="CalCellBorder" TargetType="{x:Type Border}">
<Setter Property="BorderBrush" Value="Black"/>
<Setter Property="BorderThickness" Value="0.5" />
<Style>
</UserControl.Resources>
You can then do:
<Border Grid.Column="5" Grid.Row="5" Style="{StaticResource CalCellBorder}"/>
|
|
|
|
|
The first thing that jumped out at me is that you are not nesting the controls. The way it stands now, the Canvas and Label elements will end up on top of instead of inside the Borders in the same grid cell. My guess is that you are using the Rectangles as a background color for certain cells; if so, you can use the Background property of the Border instead.
Personally, I would use the lighter-weight TextBlock instead of Label (which unlike its Forms cousin can show a wide range of content) if all you will show is text.
As for the using a Canvas, if all you want to do is put the date in the cell, I would again use a TextBlock inside the Border and change the Text property to match the day you need.
|
|
|
|
|
Hi All,
Is this possible? You have a button in the UI with its content property set as:
XAML:
<Button x:Name="btn" Content="Original Value" />
Then in your C# code you change that Content property to be something else like:
CS:
btn.Content = "New Value";
Can you subsequently access the original value set in XAML without the need for doing something like this in more C#:
btn.Content = "Original Value";
I can't even seem to find the array of _effectiveValues for a button in Visual Studio ...
|
|
|
|
|
They both count as the local value so I think your better off keeping track of the original value yourself. If you set the xaml value using a style you could do it but that seemed to be an ugly hack.
|
|
|
|
|
Using an attached property to store the original value works quite well. You probably wouldn't want to declare the attached property in a window as I have done.
<Button x:Name="b" Click="b_Click" local:Window1.OriginalContent="OriginalValue" />
void b_Click(object sender, RoutedEventArgs e)
{
var newValue = "New Value";
var original = GetOriginalContent(b);
b.Content = b.Content.Equals(newValue) ? original : newValue;
}
#region OriginalContent Attached Property
public static readonly DependencyProperty OriginalContentProperty = DependencyProperty.RegisterAttached("OriginalContent", typeof (object), typeof (Window1), new UIPropertyMetadata(Changed));
private static void Changed(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((ContentControl) d).Content = e.NewValue;
}
public static object GetOriginalContent(DependencyObject d)
{
return d.GetValue(OriginalContentProperty);
}
public static void SetOriginalContent(DependencyObject d, object value)
{
d.SetValue(OriginalContentProperty, value);
}
#endregion
|
|
|
|
|
Interesting idea ...
When I get to work in a couple of hours I'll dig out the code that I used to get at the _effectiveValues and see if anything can be done with that. I'll post it here as well.
Urgh, I feel sick just thinking about it!!
Thanks for this Dave.
|
|
|
|
|
Indeed, I was looking through the results of the LocalValueEnumerator and trying ReadLocalValue etc ...
I've had lots of fun in the past coding round the _effectiveValues array. Its really not pretty code at all. According to one thing I read this whole area of WPF is 'unfinished'. I just hope that in the next version some of this stuff is 'fixed' or 'completed'.
|
|
|
|
|
I've just tried this:
object _buttonContent = btnLoadData.ReadLocalValue(ContentProperty);
if (_buttonContent != DependencyProperty.UnsetValue && _buttonContent != null)
{
Type tx = _buttonContent.GetType();
PropertyInfo pinfo = tx.GetProperty("Content");
if (pinfo != null)
{
object objPropertyValue = pinfo.GetValue(_buttonContent, null);
string BtnContent = objPropertyValue as string;
}
}
No luck, as you say they both count as local values. There doesn't seem to be any way of 're-reading' the XAML Content="Original Value" ...
That just seems absolutely NUTS to me ... it must be doable ... surely ...
|
|
|
|
|
Hi,
i'm quite nobbie with C# and WPF but it seems as very interesting to me...
here is my question, how can i make custom main frame look with wpf
i know for the property "WindowStyle..." but i need to change default style...
is ti possible to override the default style form and how?
the reason is simple, i want my application to look the same on every windows version with every
|
|
|
|
|
You make so the window has no border and then you can WPF elements to alter the appearance of the window. If you want to make the windows look the same: create one window with the appearance you want, then make the other windows inherited from the original one.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
|
Ok,
how can i make all other elements look the same
like chack boxes, text fields, dropDown lists etc ???
|
|
|
|
|
You can define styles for the controls that will be automatically applied. If you want to do this, I would expect that you have Blend installed - it makes things easier for you.
|
|
|
|
|
i'm searching all around codeproject for some article about exactly that but i can't find it :$
if you know any, could you provide me with link please
|
|
|
|
|
Do an article search for articles by Josh Smith or Sacha Barber.
|
|
|
|
|
i already found some of their articles,
thank you..
however, it's seemed to me that they are too much concrete about topics
but i'll try to look deeper in to WPF on MSDN
thank you
|
|
|
|
|
Your best bet would be to buy a good book on WPF to learn about control styling. I would suggest any of the WPF books from Apress, they have been great additions to my book collection.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my Blog
|
|
|
|
|
|
Josh Smith and Sacha Barber write BRILLIANT articles on WPF ... study them intently ...
|
|
|
|
|
I have an ASP.NET control that I bought and I want to use it inside a SL application. Does anyone know how can I do that?
Thanks.
|
|
|
|
|
You can't use ASP.NET in XAML so does Silverlight. But you can show ASP.NET control over Silverlight control. It's all about CSS and HTML thing. Just overlay it on Silverlight DIV.
|
|
|
|