|
Using SL3/VS2008:
I'm (still) trying to render text on a bitmap. Tim Yen suggested using WriteableBitmap , and even that doesn't seem to work for me. I've tried it two different ways:
Label label = new Label();
label.Style = this.Resources["TitleBaseStyle"] as Style;
label.Content = "WHMC";
<br />
WriteableBitmap bmp = new WriteableBitmap(60, 60);
bmp.Render(label, new TranslateTransform());
bmp.Invalidate();
<br />
Image image = new Image();
image.HorizontalAlignment = HorizontalAlignment.Center;
image.VerticalAlignment = VerticalAlignment.Center;
image.Width=60;
image.Height=60;
image.Source = bmp;
this.testImage.Child = image;
...and...
Label label = new Label();
label.Style = this.Resources["TitleBaseStyle"] as Style;
label.Content = "WHMC";
<br />
WriteableBitmap bmp = new WriteableBitmap(label, new TranslateTransform());
<br />
Image image = new Image();
image.HorizontalAlignment = HorizontalAlignment.Center;
image.VerticalAlignment = VerticalAlignment.Center;
image.Width=60;
image.Height=60;
image.Source = bmp;
this.testImage.Child = image;
In the interest of completeness, here's the label's custom style:
<Style x:Key="TitleBaseStyle" TargetType="dataInput:Label">
<Setter Property="Width" Value="60" />
<Setter Property="Height" Value="30" />
<Setter Property="Background" Value="Black" />
<Setter Property="Foreground" Value="White" />
<Setter Property="FontSize" Value="17" />
<Setter Property="Padding" Value="0" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
</Style>
...and here's the container for the image:
<Border x:Name="testImage" BorderBrush="Black" Background="Red" BorderThickness="1" Margin="10"/>
Neither method results in an Image with anything visible in it (all the pixels in the WriteableBitmap object are null). This is driving me insane. What the hell am I doing wrong?
Just to make sure the label was being created as expected, I also did this, and it is displayed as expected:
Label label = new Label();
label.Style = this.Resources["TitleBaseStyle"] as Style;
label.Content = "WHMC";
this.testImage.Child = label;
I'm at a total loss...
EDIT ==================
I downloaded the WriteableBitmapEx assembly from codeplex because it contains a Clear(Color) method (like the GDI Bitmap class does). If I don't call bmp.Render(label) , the image does in fact get displayed. If I put the bmp.Render(label) back into the code, the image does NOT display.
Side note: If I call bmp.Clear(Color.Transparent) (and remove the Render(label) line), the rendered image has a whiteground, despite the Image object being placed in a red-filled Border container.
WTF?
.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
|
|
|
|
|
|
Well, that was the beta version of SL3. In the release version the Lock functionality is missing, as is the ability to set the PixelFormat via a constructor parameter.
.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 John,
I wrote this very quick and it seems to work just fine. The only thing is that you need to click the button twice!! That I dont know why?
<UserControl x:Class="SilverlightApplication5.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
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" xmlns:dataInput="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.Input">
<UserControl.Resources >
<Style x:Key="TitleBaseStyle" TargetType="dataInput:Label">
<Setter Property="Width" Value="60" />
<Setter Property="Height" Value="30" />
<Setter Property="Background" Value="Black" />
<Setter Property="Foreground" Value="White" />
<Setter Property="FontSize" Value="17" />
<Setter Property="Padding" Value="0" />
<Setter Property="HorizontalAlignment" Value="Center" />
<Setter Property="HorizontalContentAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="RenderTransformOrigin" Value="0.5,0.5" />
</Style>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="White">
<Button Content="Button" Height="23" HorizontalAlignment="Left" Margin="156,190,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />
<dataInput:Label Style="{StaticResource TitleBaseStyle}" Height="23" HorizontalAlignment="Left" Margin="81,190,0,0" Name="label1" VerticalAlignment="Top" Width="57"/>
<Image Height="91" HorizontalAlignment="Left" Margin="137,93,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="110" />
</Grid>
</UserControl>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Media.Imaging;
namespace SilverlightApplication5
{
public partial class MainPage : UserControl
{
public MainPage()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
label1.Content = "WHMC";
WriteableBitmap bmp = new WriteableBitmap(60, 60);
bmp.Render(label1, new RotateTransform() { Angle = 0 });
bmp.Invalidate();
image1.HorizontalAlignment = HorizontalAlignment.Center;
image1.VerticalAlignment = VerticalAlignment.Center;
image1.Width = bmp.PixelWidth;
image1.Height = bmp.PixelHeight;
image1.Source = bmp;
}
}
}
|
|
|
|
|
|
Looking ta the code your using an Image in the XAML
John was using a Border
Good answer
|
|
|
|
|
I gave up on this and found another (albeit clunky) solution to the problem I was trying to solve (and the solution has nothing to do with drawing bitmaps, so there's no solution to this particular problem posted).
.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
|
|
|
|
|
So Silverlight 4 gives us a RichTextBox, and the RichTextBox gives us an attribute to get the content in Xaml, but there is no way of getting the standard RTF text (compatible with the RTF 1.5 / 1.6 specification)... Or is there?
____________________________________________________________
Be brave little warrior, be VERY brave
|
|
|
|
|
There is another[^] text box available for silverlight - not sure if this meet RTF specifications.
|
|
|
|
|
Thanks, but the replies further down mentions that it is not aligned with the standard RTF format
____________________________________________________________
Be brave little warrior, be VERY brave
|
|
|
|
|
How do I add event to calendar ??
Do any control ready made available which allow me to add event to calendar
control of silverlight ??
Thx in Adv.
Jinal Desai - LIVE
|
|
|
|
|
The silverlight toolkit has a date control and an experimental global calendar control.
The toolkit is open source so you can play around with the source code for these controls.
|
|
|
|
|
I know it buddy.
But I want something that is ready made. I have no time to play
on built in controls.
So if anybody has any idea on it then post reply.
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
I've a dataGrid in my XAML file. I need to display two separate context-menus on right-click on Rows and Header. Having same context-menu on both is easy, but how to have different ones? Will someone please provide a bit of code?
|
|
|
|
|
I think, I've got the answer.
<!--ContextMenu Definition-->
<ContextMenu x:Key="cm_rowMenu">
<!--ContextMenu For Row-->
</ContextMenu>
<ContextMenu x:Key="cm_columnHeaderMenu">
<!--ContextMenu For Header-->
</ContextMenu>
<!--ContextMenu Definition Ends-->
<!--Default Header Style-->
<Style x:Key="DefaultColumnHeaderStyle" TargetType="{x:Type Custom:DataGridColumnHeader}">
<Setter Property="ContextMenu" Value="{StaticResource cm_columnHeaderMenu}" />
</Style>
<!--Default Row Style-->
<Style x:Key="DefaultRowStyle" TargetType="{x:Type Custom:DataGridRow}">
<Setter Property="ContextMenu" Value="{StaticResource cm_rowMenu}" />
</Style>
<!--Setting styles for DataGrid-->
<Custom:DataGrid
RowStyle="{StaticResource DefaultRowStyle}"
ColumnHeaderStyle="{StaticResource DefaultColumnHeaderStyle}"/>
|
|
|
|
|
Yup - that looks like it should do it.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hello, i am very new to WPF and so far i like it more than WinForms.
Currently i have a template for ListViewItems. And i want to change the selected style. When i select an item, i see blue background.
Can anyone tell me where shoud i look into?
|
|
|
|
|
In WPF, the selected item background colour is determined by System.HighlightBrush. This means that you can define a brush for the style and use SystemColors.HighlightBrushKey to set this. Here's a sample:
<Style TargetType='ListViewItem'>
<Style.Resources>
<SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}" Color="Red" />
</Style.Resources>
</Style>
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Wow, thank you. I didn't ever knew it was possible to override system colors
|
|
|
|
|
You are most welcome. Ain't WPF cool?
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Pete O'Hanlon wrote: Ain't WPF cool?
I am asking mysely: Why didn't i tried this before
Now i have a diffrent problem. I do not think it is alrigt to contiune new post, but here it is:
This is a stripped down event Template for a ListViewItem template
<DataTemplate x:Key="ListBoxItemPodjetjeTemplate">
<Grid Margin="2">
<Border Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" BorderThickness="0" Background="#8098D8D8" CornerRadius="4,4,4,4"/>
</Grid>
<DataTemplate.Triggers>
<Trigger Property="Control.IsMouseOver">
<Setter Property="Control.Background" Value="LightGreen"/>
</Trigger>
</DataTemplate.Triggers>
</DataTemplate>
I put Highlight color to transparent, now i want to change background of an item based on mouse over. Now the trigger is throwing me an exception with an inner text: {"'{DependencyProperty.UnsetValue}' is not a valid value for property 'IsMouseOver'."}.
Thank you in advance
|
|
|
|
|
What value are you applying? You haven't actually set one in the Trigger. Try changing it to
<Trigger Property="Control.IsMouseOver" Value="True" />
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Aw stupid me. Thank you for your reply
|
|
|
|
|
No problems - it's easy to miss something like this. As a hint, if you ever see a message about DependencyProperty.UnsetValue then it means the value the DP expects hasn't been set. This isn't the same as a null value because null might be a legitimate value for the DP.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
I'm trying to learn WPF doing some simple stuff before tackling a real project. The first thing I've tried to do is to mock up an Excel sheet used to review case files. It uses 40 some columns to collect reviewers' input. At least 5 columns use the same Excel data validation to limit the responses to:
Yes,
No, or
Unknown
So..in porting this to SQL Server I've put check constraints in that require one of those 3 entries.
In mocking up the data entry form in WPF I would like to use a combobox that IS BOUND to one of those SQL columns and offers the 3 permissible choices. It seems to me that the ideal approach would be to create a template combobox with the 3 choices, and then use and re-use the template for each of the constrained columns.
Maybe my searching skills are poor, but I can't seem to find any explanations or examples of doing something like this, even though it seems as though this sort of thing would be used often.
Where do I start?
|
|
|
|