|
|
[REDACTED]
Found this[^]
If it's not broken, fix it until it is
modified 30-Jun-16 15:02pm.
|
|
|
|
|
I am starting a new WPF project that's framework is going to be some sort of a tabbed view dashboard. In ASP I would use a master page with a tab control and a content page for each view. I am new to XAML and was hoping that someone knew of a basic article with example code to get me started. If anyone can point me in the right direction that would be great.
-- modified 28-Jun-16 18:47pm.
|
|
|
|
|
You're going to have to read this[^] a few times but it should give you a fair idea about how to pull together an application that suits your needs.
This space for rent
|
|
|
|
|
Sacha Barber[^] has written a load of excellent articles on WPF, from beginner to advanced framework.
|
|
|
|
|
In WPF:
There is a "main window" that would correspond to your "master page".
You can add a WPF "Tab Control" (to the window) that can contain multiple "Tab Item" controls.
The "content" for each tab can be added directly (e.g. as Text Blocks (labels), Text Boxes, Buttons, etc.); however, one generally creates "User Controls" to package UI elements into a view / content page which would then be added to a tab (as a child).
WPF uses "styles" in a way that is similar to CSS in order to propagate styling throughout the visual tree (of UI elements).
|
|
|
|
|
The article below makes doing WPF views just like MVC:
<a href="http://www.codeproject.com/Tips/678020/Master-page-in-WPF">Master page in WPF?</a>[<a href="http://www.codeproject.com/Tips/678020/Master-page-in-WPF" target="_blank" title="New Window">^</a>]
|
|
|
|
|
I have a models project with a base model. In the base model I have:
public class ModelBase : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void RaisePropertyChanged(string propertName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertName));
}
}
} The model has:
public class MonthViewDayModel : ModelBase
{
private bool _IsVisible;
public bool IsVisible
{
get { return _IsVisible; }
set
{
if (_IsVisible != value)
{
_IsVisible = value;
RaisePropertyChanged("IsVisible");
}
}
}
} When I step into the base the PropertyChanged event is ALWAYS null, yet I'm bound to these models in the XAML. The DataContext is being set.
What's wrong here?
If it's not broken, fix it until it is
modified 29-Jun-16 3:53am.
|
|
|
|
|
This is my base model handler - you seem to missing the assignment, caveat I have not looked at this in years!
public void OnPropertyChanged(string propertyName)
{
PropertyChangedEventHandler handler = this.PropertyChanged;
<pre>
if (handler != null)
{
if (propertyName != "IsDataChanged")
{ IsDataChanged = true; }
handler(this, new PropertyChangedEventArgs(propertyName));
}
}</pre>
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
That looks OK (though I would prefer to copy the eventhandler and test that copy for null, but that should make a difference in rare cases only).
Where did you set the break point to step into that code? Was that action initiated by some change in the GUI?
|
|
|
|
|
Could you post your XAML that goes along with your view model code? From what it looks like here its all set up right on your code end.
|
|
|
|
|
Anyone know where I can find something like[^] this except for everything in WPF?
If it's not broken, fix it until it is
|
|
|
|
|
|
We have a MindFusion.RealTimeCharting control that has been extensively modified by us, so talking to them probably won't help.
On a tab control I have User Control, and in that is the WinForms chart control. We want to create a report from the UI. A "Report" is an image that's created and opened in Windows Photo Viewer.
For the purposes of reporting I've written a class called PrintLib that takes the element you want to print, creates an image of it, and opens the Windows Photo Viewer with the image displayed.
The problem is that the actual contents of the chart, a Sine Wave, doesn't show up. To correct this we added a function to the chart control called 'GetPrintBitmap' which returns a DrawingVisual. We then have to call this in code to produce an image file which is the used to replace the image of the XAML element at runtime.
What we would like is to have this happen when the element is rendered. Basically, we need to force WPF to draw the Sine Wave from the WinForms control when the XAML element image is created.
What I have now does work, except that I have to call a function in the WinForms control to get the bitmap back. Here's what I do have:
The process starts here. Element is the outer control containing the User Control, which contains the WinForms control:
public void Print(ItemsControl element)
{
ChartViewModel vm = ChartCollection[0];
RealTimeChart chart = vm.GetChart();
var dv = chart.GetPrintBitmap();
PrintLib.GenerateReport(element, dv);
}
Here is the significant portion of the GenerateReport method:
public static void GenerateReport(FrameworkElement element, DrawingVisual dv)
{
App.Current.Dispatcher.Invoke(() =>
{
var width = (int)element.ActualWidth;
var mainImageName = string.Empty;
if (dv == null)
{
mainImageName = CreateImageFromView(element, width);
}
else
{
mainImageName = DrawImage(dv, width, (int)element.ActualHeight);
}
.
.
.
});
}
private static string CreateImageFromView(FrameworkElement element, int width)
{
var rect = VisualTreeHelper.GetDescendantBounds(element);
var dv = new DrawingVisual();
using (var ctx = dv.RenderOpen())
{
var brush = new VisualBrush(element);
ctx.DrawRectangle(brush, null, new Rect(rect.Size));
}
var height = (int)element.ActualHeight;
if (height == 0)
{
height = (int)element.Height;
}
if (height == 0)
{
var message = "UI Element height is 0 and is not valid";
Debug.Print(message);
throw new ArgumentException(message);
}
return DrawImage(dv, width, height);
}
private static string DrawImage(DrawingVisual dv, int width, int height)
{
var rtb = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Pbgra32);
rtb.Render(dv);
var encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(rtb));
var fileName = GetUniqueFileName("png");
using (var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.None))
{
encoder.Save(fs);
}
return fileName;
}
So essentiially we don't want to have create the DrawingVisual from the WinForms control in code. Is it possible to get WPF to render the WinForms control's contents when it renders the rest of it?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
Based on your description, and WYSIWYG, I would just capture the Window's client area as an image.
Lots of C# code around to do that.
|
|
|
|
|
That's what my code already does, the problem is that the WinForms portion doesn't render as part of the WPF rendering process, so I'm calling a method on the WinForms control to return it's visible area as a bitmap, then replacing it ove the Winforms control.
I was hopeing there weas some way of forcing the WinForms control to render in the WPF rendering when the entire view is rendered.
If it's not broken, fix it until it is
|
|
|
|
|
There's a (free) WPF chart control; why do you need to use the "Windows Forms" control? (I didn't think that control was that special).
|
|
|
|
|
Hello Every One, I have a Critical Problem in my WPF Ink Canvas. The Problem is , when i draw something on it using mouse move , it draws easily , but when my application run on other system, which have 1280*720 screen Resolution, that time Ink canvas draws shape outside the drawing area and the shape is not visible also.
my development Machine screen Resolution - 1680*1050 and when i run this application on low level Resolution Machines then Ink canvas drawing area expand and shapes are draw outside the canvas , and they are not visible also. I already tried the viewbox control, but i am not getting which i want.
Please solve this Problem as soon as possible if anyone have the solution of It.
|
|
|
|
|
Use a
ScrollViewer control.
|
|
|
|
|
I have a UI with a MainWindow, which has a tab control. Some of those tabs have child tabs. So for Main Tab 1 there are 3 Child Tabs.
When the user selects Main Tab 1, Child Tab B, then clicks File->Print on the menu, how would you pass that menu command to the Active tab? Or somehow notify the ACTIVE TAB to print?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
Bind the TabControl.SelectedIndex
<telerik:RadTabControl Grid.Column="2" SelectedIndex="{Binding SelectedTab,Mode=TwoWay}">
Telerik has that property not sure if the standard TC does.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Did you even read the question?
What does binding the tab's SelectedIndex have to do with the Menu's Print command getting paassed all the way down the visual tree??
If it's not broken, fix it until it is
|
|
|
|
|
I assumed you are doing the printing from the VM, forgot you have your odd printing method.
Still I would do it the same anyway, tab changed is bound to the VM and sets the active tab, Print command tells a VM property for each tab to print. Seems like a complete kludge but then you have a creative printing method!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
If the TabControls are implemented as a List of Lists of TabControls (or similar) in your AppComposer file (or App.xaml.cs, wherever you defined them), you could just go through said list(s) and look for the TabControl.SelectedTab property.
Once you get hold of the active/selected tab that way, you could notify it to print.
Edit:
Just noticed that's about the same as what Mycroft suggested...but I would go for it as a first approach anyway
|
|
|
|
|
Does anyone know how to change the Spell Checking language of a WPF TextBox control to UK English.
I have tried setting Language="en-GB' and xml:lang="en-GB" as advised on all the websites - it does not work!
The software I am writing is literacy software (XAML Front end, C# Code Behind) for an education centre and needs to spell check in UK english
It seems really strange that WPF does not support UK English
- Windows does??
I have done this in a previous version of the software, but I think I implemented it as WinForms and maybe used a Word Interop for spell checking - but I cannot be sure that the users will have Word installed . . .
Please, Please, Help!
I read somewhere I can add a custom dictionary for UK English
anyone know where I can get one in .lex format
I have a file with all the differences between UK and US English - can I use this somehow
|
|
|
|