|
Hi,
I'm busy with a Silverlight 5 project in which it's needed to upload PDF docs. A manager should be able to quickly preview these docs in the app. So all I need is to have a way to view the PDF contents in my Silverlight app. I have found a few solutions on the net, but almost all of them have a whole list of other features I will never use and as a result cost an arm an a leg.
So I thought the easiest way would be to convert the PDF pages into images as silverlight has no trouble displaying images. All I should need is a way to open the doc and then convert each page into an image. I'd like to be able to do this without a round trip to the server.
I know I can use an IFrame in a popup or something on top of the silverlight app, but right now that's my last resort.
Hope you can help,
Thanks
|
|
|
|
|
I'm trying to do this
<TextBlock Text="{Binding Path=Caption}"
Foreground="SlateBlue"
FontSize="14">
<TextBlock.Triggers>
<DataTrigger Binding="{Binding IsCurrentItem}" Value="True">
<Setter Property="FontWeight" Value="Bold"/>
</DataTrigger>
<DataTrigger Binding="{Binding IsCurrentItem}" Value="False">
<Setter Property="FontWeight" Value="Normal"/>
</DataTrigger>
</TextBlock.Triggers>
</TextBlock>
and it won't compile with
Cannot find the static member 'FontWeightProperty' on the type 'ContentPresenter'.
How can I set the font weight based on a bool in my data model?
If it's not broken, fix it until it is
|
|
|
|
|
<Setter Property="TextBlock.FontWeight" Value="Bold"/>
|
|
|
|
|
Ok, that now compiled. When I run it, I get:
Triggers collection members must be of type EventTrigger.
Not even sure what that means.
If it's not broken, fix it until it is
|
|
|
|
|
Unfortunately, you can only use triggers like that in a Style. So define a Style for the TextBlock, and put your triggers in there.
(Yes, it's very annoying)
|
|
|
|
|
You need to call a DataTrigger from inside a style. Now, what you could do is set the style up so that you set the FontWeight normally, and then you would only have to apply the condition to change the weight. You don't actually need both conditions, because styles always revert back to their defaults when the trigger condition is no longer met.
|
|
|
|
|
Ok, I'v been working with this, but I can't get it quite right.
I have a disabled list which acts as a table of contens for a series of 'pages'. When a page becomes active, the TOC item for it needs to be bold.
So here's my list:
<ListBox Grid.Row="1"
Grid.Column="0"
Width="225"
ItemsSource="{Binding TOC}"
BorderBrush="SlateBlue"
BorderThickness=".5"
Padding="10"
IsEnabled="False">
<ListBox.Resources>
<DataTemplate DataType="{x:Type models:TOCModel}">
<StackPanel Orientation="Horizontal"
Margin="2">
<TextBlock Text="{Binding Caption}">
</TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.Resources>
</ListBox>
and here's my style:
<Style TargetType="{x:Type ListBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBox}">
<Grid Width="Auto"
Height="Auto">
<Border x:Name="Border"
BorderBrush="SlateBlue"
BorderThickness=".5"/>
<ScrollViewer Focusable="false"
IsTabStop="False"
Margin="8"
HorizontalScrollBarVisibility="Disabled">
<StackPanel IsItemsHost="true"/>
</ScrollViewer>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Background" Value="White"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Setter Property="Background" Value="White"/>
</Style>
The list is bound to a collection of TOCModels:
public class TOCModel
{
public string Caption { get; set; }
public bool IsCurrentItem { get; set; }
}
I think I need a DataTemplate for the TOC Items to set the FontWeight to bold when IsCurrentItem = true, but I don't know where to add it.
Could use some help.
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
Add the following style:
<Style TargetType="{x:Type ListBoxItem}">
<Setter Property="FontWeight" Value="Normal" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsCurrentItem}" Value="True">
<Setter Property="FontWeight" Value="Bold" />
</DataTrigger>
</Style.Triggers>
</Style> This will get applied to all ListBoxItem elements and set the font weight appropriately.
|
|
|
|
|
how i can create graph in wpf
santy143all
|
|
|
|
|
By writing some code. Seriously, this is not a good question, if you paste this into Google you will get lots of suggestions which you can at least learn from.
|
|
|
|
|
There are a number of third party tools that you could use to implement charts.
The WPF / Silverlight toolkit itself has its own set of chart controls that you can use.
|
|
|
|
|
|
I have ViewModel that has implement IDataErrorInfo interface. Binding is working fine but Now I have a requirement that error Template should not be shown until user lost focus through the Text Box. Currently when form Loaded all the fields are validated and showing red border.
WANTED wasim khan(Killed 50 Innocent Buggs, Distroyed 200 Exception, make 5 Project Hostage) any Compnay Hire him will pay 30,000. Best place where u can get him is Sorcim Technologies Murre Road RWP
|
|
|
|
|
You could toggle a boolean variable that is set when you are loading data and reset once this is done.
Only allow the validation code to run when the state of the bool is false.
E.g.
If (!load)
{
}
|
|
|
|
|
I'm working on some code that will ultimately be used in a Windows service, but right now it's in a console app for easier development.
I want to render a WPF TextBlock control to an image. I'm trying to use RenderTargetBitmap , and it's creating a png file on the expected dimensions, but the file is empty (well, it's 2K in size, but there's nothing in it).
Can anyone tell me how to do what I'm trying to do?
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "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
|
|
|
|
|
After reading your question, I did a search and came across this article[^].
Maybe wrapping the visual into a VisualBrush and then painting the DrawingContext is what you are looking for?
The author has attached a small sample program as well.
|
|
|
|
|
Well, that example assumes a complete WPF app, which isn't what I'm doing (remember, I'm doing a console app/windows service), but I'll see if it works...
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "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
|
|
|
|
|
No change.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "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
|
|
|
|
|
*Groan* I honestly thought this fix would help you.
I wonder what the issue is?
|
|
|
|
|
I was honestly hoping it would.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "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
|
|
|
|
|
John, without the WPF rendering subsystem being involved, you won't have the necessary infrastructure in place to render out your bitmap. You are missing a Dispatcher , which means that you cannot allocate a MediaContext instance.
|
|
|
|
|
I don't want to actually see the control, I just want to render it to an image, and save it as a PNG. Should I create a WPF class library and use it from my console app? This code will ultimately be located in a Windows service.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "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
|
|
|
|
|
I'm starting with xaml created in a scene editor. This xaml is comprised of just the textblock definition. I thought the problem might be because the textblok isn't in a container of any kind, so I created a canvas, and put the textblock in it before trying to render it.
Here's my code:
private readonly XNamespace _xamlNS = @"http://schemas.microsoft.com/winfx/2006/xaml/presentation";
private readonly XNamespace _sysNS = @"clr-namespace:System;assembly=mscorlib";
private readonly XNamespace _xNS = @"http://schemas.microsoft.com/winfx/2006/xaml";
private readonly XNamespace _localNS = @"clr-namespace:System;assembly=WpfConsoleApp";
public void ImagesFromText2(string folder)
{
foreach (DynamicContentItem item in ContentItems)
{
if (item.ContentType == "text")
{
XElement container = new XElement("Canvas",
new XAttribute("xmlns", _xamlNS),
new XAttribute("xmlns:x", _xNS),
new XAttribute("xmlns:local", _localNS),
new XAttribute("Padding", "0,0,0,0"),
new XAttribute("Width", item.CanvasElement.Width.ToString()),
new XAttribute("Height", item.CanvasElement.Height.ToString()));
XElement child = item.CanvasElement.AsXElement;
string xaml = child.ToString();
child.Name = @"{http://clearchannel.com/spotchart/WpfConsoleApp}SpotChartTextBlock";
child.SetAttributeValue("Margin", "0,0,0,0");
child.SetAttributeValue("xmlns", _xamlNS);
child.SetAttributeValue("xmlns:x", _xNS);
child.SetAttributeValue("xmlns:local", _localNS);
string text = item.LocalData;
if (item.CanvasElement.IsDateTime)
{
child.SetAttributeValue("Text", item.LocalDataFormatted);
}
child.Name = @"{http://clearchannel.com/spotchart/WpfConsoleApp}SpotChartTextBlock.RenderTransform";
container.Add(child);
xaml = container.ToString();
Canvas canvas = (Canvas)(XamlReader.Parse(xaml));
SpotChartTextBlock textBlock = (SpotChartTextBlock)(canvas.Children[0]);
textBlock.VerticalTextAlignment = item.VerticalAlign;
textBlock.SizeToFit = item.SizeToFit;
textBlock.MinimumFontSize = item.MinimumFontSize;
textBlock.Process();
int width = (int)textBlock.Width;
int height = (int)textBlock.Height;
RenderTargetBitmap rtb = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);
DrawingVisual dv = new DrawingVisual();
using (DrawingContext ctx = dv.RenderOpen())
{
VisualBrush vb = new VisualBrush(canvas);
ctx.DrawRectangle(vb, null, new Rect(new Point(), new Size(width, height)));
}
rtb.Render(dv);
PngBitmapEncoder png = new PngBitmapEncoder();
png.Frames.Add(BitmapFrame.Create(rtb));
MemoryStream stream = new MemoryStream();
png.Save(stream);
System.Drawing.Image image = System.Drawing.Image.FromStream(stream);
image.Save(System.IO.Path.Combine(folder, string.Format("{0}.png", item.ElementName)));
}
}
}
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "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
|
|
|
|
|
I don't think it needs a canvas. Does textBlock.Process() call the TextBlock.Measure() and TextBlock.Arrange()? I think that because you do not render to a UI, the values are not calculated, and these functions need to be explicitly called.
Jack of all trades ~ Master of none.
|
|
|
|
|
That was it. I called measure and arrange in the process method, and she wookee velly good.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- "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
|
|
|
|
|