I'm thinking about creating a custom TreeViewItem (or at least just extending TreeViewItem to implement some custom properties). I want to add a checkbox and counter labels etc - my question is however, how do I get my tree to use the custom TreeViewItem rather than the default TreeViewItem object?
Custom TreeViewItem?
The resource could not be resolved
Hello,
Been playuing around with the listview in an attempt to build a menu. I've removed the borders but for some reason, I keep getting the following error:
The resource ListViewNewTemplate could not be resolved.
I've no idea why. I've added a resource dictionary and ensured the controltemplate is called that but still no luck
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"><ControlTemplate x:Key="ListViewNewTemplate" TargetType="{x:Type ListBox}"><Border x:Name="Bd" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" Padding="0" SnapsToDevicePixels="True"><ScrollViewer Focusable="False" Padding="{TemplateBinding Padding}"><ItemsPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/></ScrollViewer></Border><ControlTemplate.Triggers><Trigger Property="IsEnabled" Value="False"><Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/></Trigger><Trigger Property="IsGrouping" Value="True"><Setter Property="ScrollViewer.CanContentScroll" Value="False"/></Trigger></ControlTemplate.Triggers></ControlTemplate></ResourceDictionary>
and heres the main code
<Window x:Class="WpfApplication1.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="MainWindow" Height="350" Width="525"><Grid><Grid HorizontalAlignment="Left" Height="300" Margin="271,10,0,0" VerticalAlignment="Top" Width="236"><ListView Width="236" Height="300" ItemsSource="{Binding Destinations}" ItemTemplate="{DynamicResource ListViewNewTemplate}" BorderThickness="1" Template="{DynamicResource ListViewNewTemplate}" ></ListView></Grid></Grid></Window>
could not be resolved.
Where is/will the documentation for any changes to .net/WPF for Windows 10 be?
Where / When will documentation be released for what the new Windows 10 means to us WPF / C# / Desktop developers? Will there be new api's? Will there be new core underpinnings that provide for speed and functionality improvements? I would have no trouble migrating to a xaml/c# api built on the WinRT core that allows us to build WPF equivalent desktop apps, in fact I would heartily embrace it. Are we going to have one? Notice I said a WPF equivalent.
I am patient, just want to make sure that I have not missed any announcements yet about this and understand where to keep looking for any announcements.
thanks
pmont.
MVVM Light ViewModelLocator + Prism 5.0 + MEF + RegionManager = Error DelayedRegionCreationBehavior
Hello,
If my MainWindow Xaml code contains lines like
<Window x:Class="Apollo.Desktop.Shell.ShellWindow2" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:regions="http://www.codeplex.com/CompositeWPF" Title="ShellWindow2" Height="300" Width="300"><Grid><ContentControl regions:RegionManager.RegionName="MainRegion" Margin="5,0,5,5" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" /></Grid></Window>
The bootstrapper call the Shell creation and the Windows is loaded with the module inside the MainRegion
The same code with the following line anyware inside the xaml:
{Binding Source={StaticResource Locator}, Path=...}
<Window x:Class="Apollo.Desktop.Shell.ShellWindow2" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:regions="http://www.codeplex.com/CompositeWPF" Title="ShellWindow2" Height="300" Width="300" DataContext="{Binding Main, Source={StaticResource Locator}}"><Grid><ContentControl regions:RegionManager.RegionName="MainRegion" Margin="5,0,5,5" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" /></Grid></Window>
Now, when I launch, I get this error:
The composition produced a single composition error. The root cause is provided below. Review the CompositionException.Errors property for more detailed information. 1) Type not found in cache: Microsoft.Practices.Prism.Regions.Behaviors.DelayedRegionCreationBehavior. Resulting in: 'Set property 'Microsoft.Practices.Prism.Regions.RegionManager.RegionName' threw an exception.' Line number '8' and line position '6'.
Any idea how to make it work ?
Thanks in advance
-Vince
-Vince
How to use chart object with a work thread?
I am using a STA Thread for creating a chart object.
public void createChart(string name_Sigal) { //Memorisanje indexa za pretragu serije(kod prikaza svih signala na jenom grafikonu) //seria_IndexMap.Add(name_Sigal,seriaIndex); //seriaIndex++; var chunkList = dataManager.getChunkList(); var signalMap = chunkList[chunkNum].getSignalMap(); var currentSignal = signalMap[name_Sigal]; point = new zoomPoints(); zoomPointsMap.Add(name_Sigal, point); Store_endAxis_Values(name_Sigal); //Podesavanja za zajednicku osu long minRaw = minXCommonAxis();//minimalna sirova vrednost long maxRaw = maxXCommonAxis();//maksimalna sirova vrednost setRelativeOffset(minRaw); double min = minOffsetPoint();//minimalna offset vrednost double max = maxOffsetPoint();//makismalna offset vrednost //Kreiranje grafikona Chart chart = new Chart(); LineSeries lineSeria = new LineSeries(); LineSeries lineSeria_single = new LineSeries(); //Y osa LinearAxis linYAxis = new LinearAxis(); linYAxis.Orientation = AxisOrientation.Y; linYAxis.Minimum = zoomPointsMap[name_Sigal].yFirst * 4;//pomnozi sa proizvoljnim brojem da bi prikaz tacaka bio bolji(ako ostane tacma na samoj liniji max ili min nece se dobro videti) linYAxis.Maximum = zoomPointsMap[name_Sigal].yLast * 4; linYAxis.Interval = (linYAxis.Maximum - linYAxis.Minimum) / numOfIntervalY; linYAxis.FontSize = 8; //X osa LinearAxis linXAxis = new LinearAxis(); linXAxis.Orientation = AxisOrientation.X; linXAxis.Location = AxisLocation.Bottom; linXAxis.Minimum = min; linXAxis.Maximum = max; //linXAxis.Interval = (linXAxis.Maximum - linXAxis.Minimum) / numOfIntervalX; //Popunjavanje vrednosti za dati signal Queue<KeyValuePair<double, long>> signalValues = new Queue<KeyValuePair<double, long>>(); foreach (var el in currentSignal) signalValues.Enqueue(new KeyValuePair<double, long>(el.Key.relativeTime, el.Value)); //Podesavanja za seriju(podeljeni grafikoni) lineSeria.ItemsSource = signalValues; lineSeria.Title = name_Sigal; lineSeria.DependentValuePath = "Value"; lineSeria.IndependentValuePath = "Key"; lineSeria.IndependentAxis = linXAxis; lineSeria.DependentRangeAxis = linYAxis; //Line seria za single graph lineSeria_single.ItemsSource = signalValues; lineSeria_single.Title = name_Sigal; lineSeria_single.DependentValuePath = "Value"; lineSeria_single.IndependentValuePath = "Key"; var customStile = this.Resources["customStyle"] as Style; lineSeria.Style = customStile; lineSeria_single.Style = customStile; //Dodavanje pojedinacnih serija u mapu serija seria_SeriaMap.Add(name_Sigal, lineSeria_single); //Dodavanje serije grafikonu i dodela velicine chart.Series.Add(lineSeria); //Dodavanje serije zajednickom grafikonu singleChart.Series.Insert(seria_IndexMap[name_Sigal], lineSeria_single); //Podesavanje sirine var chartWidth = 0.0; Dispatcher.BeginInvoke(new Action(() => { chartWidth = scroll.ActualWidth * sectionNumbers(); })); chart.Width = chartWidth; setSameWidth(); //Dodaj grafikon u mapu kreiranih grafikona SharedResoures.chartMap.Add(name_Sigal, chart);
setStyle(name_Sigal); }
When it is created, a chart object is moved to the chartMap which is created at main thread. When i try to change a style like this:
public void setStyle(string signalName) { Style style2 = new Style(typeof(Polyline)); style2.Setters.Add(new Setter(Polyline.StrokeProperty, SharedResoures.signal_legendColor)); (SharedResoures.chartMap[signalName].Series.First() as LineSeries).PolylineStyle = style2; (singleChart.Series.ElementAt(seria_IndexMap[signalName]) as LineSeries).PolylineStyle = style2; //var ttdps = LayoutRoot.Resources["ToolTipDataPointStyle"] as Style; Style style1 = new Style(typeof(LineDataPoint), ttdps); style1.Setters.Add(new Setter(DataPoint.BackgroundProperty, SharedResoures.signal_legendColor)); style1.Setters.Add(new Setter(DataPoint.BorderBrushProperty, SharedResoures.signal_legendColor)); (SharedResoures.chartMap[signalName].Series.First() as LineSeries).DataPointStyle = style1; (singleChart.Series.ElementAt(seria_IndexMap[signalName]) as LineSeries).DataPointStyle = style1; Style legendStyle = new Style(typeof(Legend)); legendStyle.Setters.Add(new Setter(Legend.WidthProperty, 0.0)); SharedResoures.chartMap[signalName].LegendStyle = legendStyle; }
At this line
(SharedResoures.chartMap[signalName].Series.First() as LineSeries).PolylineStyle = style2;
there is always an error: The calling thread cannot access this object because a different thread owns it.
I have tried to do that in main thread with Dispetcher.BeginInvoke but again the error is the same becouse a chart object was created in the work thread(STA Thread). What should i do?
Adding a textbox to a ContainerVisual
Hi there,
I have a newbie question:
I am editing some legacy code in which there is a Class CarsView derived from System.Windows.Controls.UserControl.
CarsView comprises a DrawingCanvas, grid, scrollcontrol, etc... and to it CarLists (ContainerVisuals) are added displaying information about cars.
Each CarList has a title which is displayed through a drawingvisual added to its children and positioned at the top, so the CarLists can be dragged around the window and rearranged.
My question is - I want to click on a CarList title and have it change to an editable textbox.
Can I create a textbox and add it to the CarList, or as a ContainerVisual, does CarList only accept DrawingVisuals and not complex user controls? In which case would the textbox need to be added to the CarsView and somehow positioned over the relevant CarList?
Thanks in advance.
How can i navigate on other page using keyboard shortcut?
I've got the button and it works as expected.
<ButtonContent="PUSH ME"Command="NavigationCommands.GoToPage"CommandParameter="/Pages/Search.xaml"/>
And i'd like to add shortcut. I hope it would work, but there is no.
<Window.InputBindings><KeyBindingKey="F1"Command="NavigationCommands.GoToPage"CommandParameter="/Pages/Search.xaml"/></Window.InputBinding>
Any suggestions?
Customize Slider
Hello
I would like to customize my Slider. I 've search but the tutorials I found do not satisfy my needs.I would like to change the color of the bar and the thumbs
thank
tyring to find an equivalent to .location property in visual c# wpf
hello everyone, I program in visual c# and about a week ago I decide to move on to wpf.... now I have a label next to a textbox and the textbox is on autosize and I'm looing for a way to make the label move along as the texbox grows... now in winform c# I used a code like this:
this.label4.Location =newPoint(textBox1.Location.X + textBox1.Size.Width, textBox1.Location.Y +2);
I need something like that in wpf that don't include using canvas, grids or panels.
is it possible?
Touch services in WPF halt randomly
Hello,
Months ago I've developed a WPF application running on a Panasonic Toughpad and classified for critical usage. A few weeks ago we noticed a random phenomena where all touch events cease to work, entirely.
It turns out this is a known and documented bug, and that the bottom line is WPF cannot be trusted when it comes to touch. This is 2014, touch is king, Windows 8 is very much touch oriented, laptops, why on earth can't WPF support touch correctly? What if mouse functionality would suddenly cease to work when the user moves the cursor at a certain speed?
I'd appreciate a fix/workaround for the described issue, noemata offered a fix (!) and even his direct help (!)
Can someone from Microsoft please respond?
Thank you!
How to add code only window file to my project?
Hi all,
The windows class (.net 4) shows an example in msdn on how to define a code only window file:
http://msdn.microsoft.com/en-us/library/system.windows.window(v=vs.100).aspx
I want to add this file to my project (named myProject) so I can set the window size at runtime after I do some calculation on my data. The window may be in "portrait" or "landscape" but I won't know that until after the calculations.
I tried to add a code file to my project but it is blank. I copy/paste the code and changed the namespace to myProject but I get an error if I call CodeOnlyWindow() from any of myProject other windows (There are several of them. All with their xaml files).
How can I do this?
Thanks
Does MVVM require a toolkit -- like Prism or MVVM light or some other toolkit or template -- or can WPF use MVVM right out of the box?
I am now in a role where I have all kinds of creative liberty, and the sky is the limit (lim┬(n→∞)). My problem is that I still don't quite have a handle on MVVM yet. I think part of my confusion is that I don't actually know if MVVM requires a toolkit. If yes, then that will clear things up a little bit for me.
I need to start crackin on this because I have stuff I need to deliver -- Ideally with WPF and MVVM. Let's see -- for review of MVVM, a few of the elements include a DataContext in the main xaml file, you have a Delegate Command, ICommand, INotifyPropertyChanged Interface, an ObservableCollection, Of course, the main structure -- a Model Class, a ViewModel class, a View xaml file -- to name a few elements.
Question: is the observable collection optional? Or is it required in order to consider a pattern real MVVM?
I have a sample app (VS2012) at
which does not appear to use any toolkits like Prism or MVVM Light or anything else. Was this sample created right out of the box? I don't have Prism or MVVM Light or anything other toolkit (unless Blend is considered a toolkit -- I have that) on my current workstation (win7 pro).
Note: I have enough understanding/proficiency in winform programming to be able to be employed doing that. I realize that winform has some limitations, and these limitations are overcome by WPF/MVVM (or at least the limitations are reduced). So here is the big question: Is WPF/MVVM "SIGNIFICANTLY" more complex than winform? or is it more likely just some mental block that I have that I'm just not getting it (but if I sledge hammer away at it enough - eventually I WILL get it)?
Rich P
Image on button background
Handle for D3DImage needed
Hello,
I need the pointer from the Microsoft.DirectX.Direct3D.Surface to use with the D3DImage-Class-Method "SetBackBuffer. The Mircosoft.DirectX.Direct3D.Device-Methods "GetBackBuffer" returns a Microsoft.DirectX.Direct3D.Surface not an IntPtr.
Thanks for help
Regards Scotty
Confused by WPF Ribbon licensing
Hi,
I'm using Ribbon in my WPF application. I downloaded "Microsoft Ribbon for WPF October 2010"(http://www.microsoft.com/en-us/download/details.aspx?id=11877), but I couldn't understand the licensing. The license stated a lot of requirements regarding Distributable Code, but I'll be shipping my product in binary form, no source code. As for whether I can make commercial use of Ribbon, whether I should include the license in my product, I'm confused.
I searched online and found this link:http://msdn.microsoft.com/en-us/office/aa973809.aspx but it has already retired.
Persist the Text in DatePicker and Highlight the border on Invalid Input
Hello,
I have two requirements for validating values in my Datetime Picker Control.
1. If I put an invalid date i.e for eg.12343a then this date should persist in datepicker. The issue I am facing is that after moving out of the control after typing such text the control automatically takes the previous valid date! I think this is the default behaviour of the MS DatePicker Control. Is there any way someone can suggest to implement the behaviour i want?
2. If I put and invalid date such as above and move out of the control then the border of DatePicker should also turn to red.
Please suggest.
Thanks.
Datagridcombobox binding with expandoobject
Hi.
I am trying to bind a datagridcombobox selected value to a property value in an expando object. However, I am not managing to do that. Maybe anyone can give me some insights into the problem.
Here are the relevant bits and peaces of the code:
XAML datagrid
<DataGrid x:Name="RXSignalsDataGrid" Grid.Column="1" CanUserReorderColumns="True" CanUserAddRows="False" CanUserResizeColumns="True" CanUserSortColumns="False" Margin="5" ItemsSource="{Binding CANRXFrameSignals}" AutoGenerateColumns="False"><DataGrid.Columns><DataGridCheckBoxColumn Header="Enabled" Binding="{Binding Property_0_Value}" Width="Auto" IsReadOnly="False"/><DataGridTextColumn Header="Start Bit" Binding="{Binding Property_2_Value}" Width="Auto" IsReadOnly="False"/><DataGridTextColumn Header="Length" Binding="{Binding Property_5_Value}" Width="Auto" IsReadOnly="False"/><DataGridCheckBoxColumn Header="Little Endian" Binding="{Binding Property_1_Value}" Width="Auto" IsReadOnly="False"/><DataGridCheckBoxColumn Header="Conversion 1 Enabled" Binding="{Binding Property_4_Value}" Width="Auto" IsReadOnly="False"/><DataGridTextColumn Header="Conversion 1 Type" Binding="{Binding Property_7_Value}" Width="Auto" IsReadOnly="False"/><DataGridComboBoxColumn Header="Conversion 1 Type" Width="Auto" IsReadOnly="False" DisplayMemberPath="Key" SelectedValuePath="Value"><DataGridComboBoxColumn.ElementStyle><Style><Setter Property="ComboBox.ItemsSource" Value="{Binding Path=SignalConversionOperators}"/><Setter Property="ComboBox.SelectedValue" Value="{Binding Path=CANRXFrameSignals.Property_7_Value}"/></Style></DataGridComboBoxColumn.ElementStyle><DataGridComboBoxColumn.EditingElementStyle><Style><Setter Property="ComboBox.ItemsSource" Value="{Binding Path=SignalConversionOperators}"/><Setter Property="ComboBox.SelectedValue" Value="{Binding Path=CANRXFrameSignals.Property_7_Value}"/></Style></DataGridComboBoxColumn.EditingElementStyle></DataGridComboBoxColumn><DataGridTextColumn Header="Conversion 1 Value" Binding="{Binding Property_8_Value}" Width="Auto" IsReadOnly="False"/><DataGridCheckBoxColumn Header="Conversion 2 Enabled" Binding="{Binding Property_3_Value}" Width="Auto" IsReadOnly="False"/><DataGridTextColumn Header="Conversion 2 Type" Binding="{Binding Property_6_Value}" Width="Auto" IsReadOnly="False"/><DataGridTextColumn Header="Conversion 2 Value" Binding="{Binding Property_9_Value}" Width="Auto" IsReadOnly="False"/><DataGridTextColumn Header="Variable" Binding="{Binding Property_10_Value}" Width="Auto" IsReadOnly="False"/></DataGrid.Columns></DataGrid>
View model:
private ObservableCollection<ExpandoObject> canRXFrameSignals; private Dictionary<string, uint> signalConversionOperators = new Dictionary<string, uint>(){ {"+",0}, {"-", 1}, {"*", 2}, {"/", 3}, {"AND", 4}, {"OR", 5}, {"XOR", 6}, {"Power", 7}, {"S +", 8}, {"S -", 9}, {"S *", 10}, {"S /", 11}, {">>", 12}, }; public ObservableCollection<ExpandoObject> CANRXFrameSignals { get { return canRXFrameSignals; } private set { if (canRXFrameSignals == value) { return; } canRXFrameSignals = value; OnPropertyChanged("CANRXFrameSignals"); } } public Dictionary<string, uint> SignalConversionOperators { get { return signalConversionOperators; } }
The data in the expando object property is of type uint. I have gotten the Dictionary to bind to the combo box, meaning that I get the elements when I click on the combo box, however it does not bind the numeric value to the ExpandoObject. However the values in the CheckBoxColumns and the TextBoxColumns are binding succesfully, thus I'm a bit confused why it does not bind in the case of ComboBox.
The error that I get is:
A first chance exception of type 'System.InvalidOperationException' occurred in System.Core.dll System.Windows.Data Error: 17 : Cannot get 'CANRXFrameSignals' value (type 'Object') from '' (type 'ExpandoObject'). BindingExpression:Path=CANRXFrameSignals.Property_7_Value; DataItem='ExpandoObject' (HashCode=8435281); target element is 'TextBlockComboBox' (Name=''); target property is 'SelectedValue' (type 'Object') InvalidOperationException:'System.InvalidOperationException: Property path is not valid. 'System.Dynamic.ExpandoObject+MetaExpando' does not have a public property named 'Items'. at CallSite.Target(Closure , CallSite , Object ) at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0) at MS.Internal.DynamicPropertyAccessorImpl.GetValue(Object component) at MS.Internal.Data.PropertyPathWorker.GetValue(Object item, Int32 level) at MS.Internal.Data.PropertyPathWorker.RawValue(Int32 k)'
Data binding tab control selected index property in multiple user controls
I have two user controls.
I want clicking on a button in one user control modify the tab index of a tab control in another user control via data binding.
The buttons are bound to the Mode enum correctly i.e. if i click either button, then the getter/setters are called for the property. However, the TabControl never updates. I;ve been searching on google and MSDN for 2 days straight and I cannot figure out how to tweak this code to get it to work correctly.
Any help would be greatly appreciated.
This is the code I have:
<UserControl xmlns:local="clr-namespace:local" x:Class="local.VMode" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="175" d:DesignWidth="300"><UserControl.DataContext><local:Memory/></UserControl.DataContext><Grid><GroupBox Header="MODE" BorderThickness="1"><Grid> <Grid.Resources><local:EnumToBooleanConverter x:Key="EnumToBooleanConverter" /></Grid.Resources><Grid.RowDefinitions><RowDefinition/><RowDefinition/></Grid.RowDefinitions><Grid.ColumnDefinitions><ColumnDefinition/><ColumnDefinition/><ColumnDefinition/></Grid.ColumnDefinitions> <RadioButton Grid.Column="0" GroupName="grpMode" Style="{StaticResource {x:Type ToggleButton}}" Content="1" HorizontalAlignment="Center" VerticalAlignment="Center" Width="48" Height="48" IsChecked="{Binding Path=Mode, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=Mode1}"/><RadioButton Grid.Column="1" GroupName="grpMode" Style="{StaticResource {x:Type ToggleButton}}" Content="2" HorizontalAlignment="Center" VerticalAlignment="Center" Width="48" Height="48" IsChecked="{Binding Path=Mode, Converter={StaticResource EnumToBooleanConverter}, ConverterParameter=Mode2}"/></Grid></GroupBox></Grid></UserControl><UserControl xmlns:local="clr-namespace:local" x:Class="local.VTabCtrl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" mc:Ignorable="d" d:DesignHeight="475" d:DesignWidth="600"><UserControl.DataContext><local:Memory/></UserControl.DataContext><Grid><TabControl SelectedIndex="{Binding Path=Mode, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" ><TabItem Visibility="Collapsed" ><GroupBox Header="Tab1"><DataGrid /></GroupBox></TabItem><TabItem Visibility="Collapsed" ><GroupBox Header="Tab2" ><TextBox Grid.Column="0" FontSize="18" FontFamily="Consolas" AcceptsReturn="True" AcceptsTab="False" CharacterCasing="Upper"/></GroupBox></TabItem></TabControl></Grid></UserControl>
using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Text; using System.Windows.Data; namespace local { public enum eMode { Mode1= 0, Mode2 }; public class Memory : INotifyPropertyChanged { public Memory() { } public eMode Mode { get { return m_Mode; } set { m_Mode = value; NotifyPropertyChanged("Mode"); } } private eMode m_Mode = eMode.Mode1; private void NotifyPropertyChanged(String propertyName = "") { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } public event PropertyChangedEventHandler PropertyChanged; } public class EnumToBooleanConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return Enum.Parse(value.GetType(), (string)parameter).Equals(value); } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { return Enum.Parse(targetType, (string)parameter); } } }
C# WPF - Interpolation and the Resize Image Quality
Hello, could guide me, I'm resizing some images using System.window.media, but can not find how to increase the level of image quality gradually. The code I have is as follows:
public BitmapFrame Redimencionar(BitmapFrame photo, double width, double height) { var target = new TransformedBitmap( photo, new ScaleTransform( width / photo.Width * 96 / photo.DpiX, height / photo.Height * 96 / photo.DpiY, 0, 0)); var thumbnail = BitmapFrame.Create(target); BitmapFrame newPhoto = Resize(thumbnail, (int)width, (int)heigth, BitmapScalingMode.HighQuality); return newPhoto; } private BitmapFrame Resize(BitmapFrame photo, int width, int height, BitmapScalingMode scalingMode) { DrawingGroup group = new DrawingGroup(); RenderOptions.SetBitmapScalingMode(group, scalingMode); group.Children.Add(new ImageDrawing(photo, new Rect(0, 0, width, height))); DrawingVisual targetVisual = new DrawingVisual(); DrawingContext targetContext = targetVisual.RenderOpen(); targetContext.DrawDrawing(group); RenderTargetBitmap target = new RenderTargetBitmap(width, height, 96, 96, PixelFormats.Default); targetContext.Close(); target.Render(targetVisual); BitmapFrame targetFrame = BitmapFrame.Create(target); return targetFrame; }
The aim is that the resulting image may be least distorted.
Thank you,
Regards.
WPF Application Error ON Windows 8 or 8.1
When I run my application on windows 7 or XP is work fine, but when I run on Windows 8 or 8.1 application generate a random exception on every start up.