|
That's not a problem. That's precisely the type of thing a ViewModel is designed to solve. Have a property backing your TextBox of type string, and then test the input there. Only pass the value on if it's an int. Alternatively, back it with a Behavior[^] to ensure the user cannot enter invalid values.
|
|
|
|
|
Thanks for the hint. I'll look into that approach.
The vaildation errors occur in the realm of the UserControl, while the Button and its command are in the realm of the Window (and its ViewModel, resp.). Things will become more complicated, but I'll try it.
|
|
|
|
|
Drop that Behavior on the TextBox and you won't need to reject ABC... because that's taken care of for you.
|
|
|
|
|
|
I have a WPF control hosted in an ElementHost in a WinForms control.
My WPF control has 5 buttons on top, a horizontal separator, and a ListBox below. The buttons have simple stlyes and images.
When I put the WPF control on a WinForms control, and also in runtime, the images and styles do not appear. The buttons appear as skinny verticle "slivers"
I've never hosted a WPF control in WinForms before. Does anyone have any idea why this is happening?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
I'm converting parts of a WinForms app to WPF.
This code is a PictureBox that has a circular area in the middle. The Paint event is used to color the circle. Then later a transparent icon is placed over it. The color is user-configurable.
Here's the WinForms control code:
public partial class ucFC6SensorPictureBox : PictureBox
{
private Color _BackgroundColor = Color.Yellow;
public Color BackgroundColor
{
get
{
return _BackgroundColor;
}
set
{
_BackgroundColor = value;
Refresh();
}
}
public ucFC6SensorPictureBox()
{
InitializeComponent();
}
private void ucFC6SensorPictureBox_Paint(object sender, PaintEventArgs e)
{
using (SolidBrush b = new SolidBrush(_BackgroundColor))
{
e.Graphics.FillEllipse(b, 1F, 1F, this.ClientRectangle.Width - 2F, this.ClientRectangle.Height - 2F);
}
if (Image != null)
{
e.Graphics.DrawImage(Image, new Point(0, 0));
}
}
}
Mu question is how to do this In WPF.
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
Something like this should do it
<Grid Width="200" Height="200">
<Ellipse HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Fill="{Binding UserDefinedColor}" />
<Image Source="{Binding ImageSource}" HorizontalAlignment="Center" VerticalAlignment="Center" />
</Grid>
|
|
|
|
|
I need to design a time scale control that scrolls horizontally. Think of a ruler with vertical lines for hours, minutes, and seconds that moves right to left as time tics.
Here's a basic idea[^]
Requirements:
- The user can decide to show Hours, Minutes, or Seconds, or all three.
- The content needs to scroll in relation to the scale shown... meaning if Minutes is selected, then every minute the scale needs to move from right to left the "width" of the space of one minute bar. The more ticks shown (seconds), the faster it moves.
- The content area needs to be dragable. Once dragging is done, the control should resume responding to timer events.
- There has to be a vertical bar that represents "now", and that bar should always be in the center. This should not be an issue since the control is moving in real time, so the center should always be the now position.
- There will be dots added to the control in real time that represent event that occurred. Clicking the dot will invoke some other action. (Don't need to code that action right now, just the dots appearing)
- I'd like to provide the option for smooth scrolling or incremental scrolling. This would probably be done using a constant motion for smooth scrolling and for incremental, it would move in response to a timer tic.
I have some ideas on how to design this, but I'd like to get some input before I start.
I've looked at this control[^] but it looks overly complex for what I want.
Thanks
If it's not broken, fix it until it is
modified 22-Apr-15 15:03pm.
|
|
|
|
|
Telerik have a timeline type control but the only time I considered it I found it dramatically over the top with functionality. I would have spent more time customising it to meet my simple needs (chopping bits out) than building a control from scratch. It may be worth looking at for your requirements.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
[SOLVED]
Found this[^]
I'm trying to create a user control that has a timer:
using System;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
namespace WpfApplication1
{
public partial class Timeline : UserControl
{
Timer timer = null;
public string CurrentTime
{
get { return (string)GetValue(CurrentTimeProperty); }
set { SetValue(CurrentTimeProperty, value); }
}
public static readonly DependencyProperty CurrentTimeProperty =
DependencyProperty.Register("CurrentTime", typeof(string), typeof(Timeline), new PropertyMetadata(""));
public Timeline()
{
InitializeComponent();
setup();
}
private void setup()
{
timer = new Timer();
timer.Elapsed += timer_Elapsed;
timer.Interval = 1000;
timer.Enabled = true;
}
private void timer_Elapsed(object sender, ElapsedEventArgs e)
{
CurrentTime = DateTime.Now.TimeOfDay.ToString();
}
}
}
When I run this it fires after 1 second, and I get a runtime exception on the DP Setter:
The calling thread cannot access this object because a different thread owns it.
I don't understand why it thinks this is in a different thread. What am I not seeing ehre?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
OnMouseDoubleClick from a selectedItem in a listview, I want to retrieve the parent of that selectedItem, and from that, populate several related listviews with the related records.
What is the best way to do this using the MVVM pattern without polluting the view with too much code-behind?
|
|
|
|
|
I hope you get a response for this as I'm a polluter, I use code behind and pass the info to the datacontext
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
The generally accepted solution is to use something like EventToCommand.
|
|
|
|
|
I'm pretty sure I told you how to do it when I answered you here[^].
|
|
|
|
|
please help to solve this issue.
Thanks in advance.
|
|
|
|
|
Err, I'm not exactly sure what you're asking here. Are you talking about how to handle the change to the appropriate date format? What code do you currently have to handle the change of culture? Have you put the basics of i18n in place in your application already?
|
|
|
|
|
I used following code to get country list in combobox and my requirement is on selecting country in combobox, date want to update in date picker with respect to current culture.
public List<string> getCountryList()
{
CultureInfo[] cultures = CultureInfo.GetCultures(CultureTypes.AllCultures & ~CultureTypes.NeutralCultures);
foreach (CultureInfo culture in cultures)
{
try
{
RegionInfo region = new RegionInfo(culture.Name);
if (!(cultureList.Contains(region.EnglishName)))<br />
{
cultureList.Add(region.EnglishName);
abbrevationtext.Add("en-" + region.TwoLetterISORegionName.ToLower());
}
}<br />
catch (Exception ex)
{
}
}
cultureList.Sort();
return cultureList;
}
|
|
|
|
|
Hi,
I'm integrating some some WPF controls into a MFC dialog box.
One of the control is a media player that shows live video.
The second one is a label that shows the current video time.
What I need is to have is the label on top of the media player. The label should only display the time, so its background needs to be transparent.
Right now, I have the video player running fine inside the dialog box, but I am unable to have the time displayed as I wish. It just overlap the video player.
Both WPF components were creating by following instructions from this link.
https://msdn.microsoft.com/en-us/library/ms742522(v=vs.110).aspx#hosting_a_wpf_page[^]
I try to set the label with a transparent background.
timeLabel->Background = gcnew System::Windows::Media::SolidColorBrush (System::Windows::Media::Colors::Transparent);
But the label background is shown black.
I also try to set the Transparent flag of the MFC CDialog to true, but it didn't have any effect.
How can I that fixed?
Do I need to set up something special when I instantiate the WPF controls?
Do I need to call some functions from inside the MFC dialog box?
Thanks,
Alain Migeon
PS This question has also been asked in "C / C++ / MFC" forum.
|
|
|
|
|
I'm trying to add a DataGridComboBoxColumn to my grid in the code behind:
public List<Person> People = new List<Person>();
People.Add(new Person { Id = 0, Name = "Joe" });
People.Add(new Person { Id = 1, Name = "Pete" });
People.Add(new Person { Id = 2, Name = "Sam" });
System.Windows.Controls.DataGridComboBoxColumn comboCol = new System.Windows.Controls.DataGridComboBoxColumn();
comboCol.Header = "People";
comboCol.ItemsSource = People;
comboCol.DisplayMemberPath = "Name";
comboCol.SelectedValuePath = "Id";
this.taskGrid.Columns.Add(comboCol);
When I run it, the column is added, but the combo does not appear in the row. What am I doing wrong here?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
Kevin Marois wrote: What am I doing wrong here
Trying to add a combo to a datagrid! Sorry I just never allow inline editing of more than the absolute minimum and NEVER allow controls to be included in a datagrid.
Having said that why not include the column at design time and set the visibility of the column at runtime.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
This is a really old question, it comes down to a server delivers responses to a request, it does not know who is asking so it cannot respond to a nothing! Polling is the most common solution to this problem.
Or you can implement messaging services, a nasty piece of work.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Xaotiq wrote: Just not as part of EF
You are correct, there was a thread recently on sql server using the notifications, had a problem if there was no change in 36 hours. I believe SignalR is also such a framework from service to client, not database to service.
I have no faith in EF and have never worked successfully with it so I can't help there.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Hi All,
we have done application using WPF .Net framework 3.5.Now I want to migrate application to .Net framework 4.5 but application building successfully.I am not able to see the design (XAML) part.
In Xaml showing many errors as below.Could you please help me out.Thanks in advance
System.ArgumentException
'{DependencyProperty.UnsetValue}' is not a valid value for the 'System.Windows.Controls.Image.Source' property on a Setter.
at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.WaitForCompletion(NestedCallContext nestedCallContext, BlockingCall call, WaitHandle timeoutSignal)
at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.MarshalOutSynchronous(Action action, Int32 targetApartmentId, WaitHandle aborted, WaitHandle timeoutSignal)
at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.MarshalOut(Action action, Int32 targetApartmentId, WaitHandle aborted, CallSynchronizationMode syncMode, WaitHandle timeoutSignal)
at Microsoft.Expression.DesignHost.Isolation.Remoting.ThreadMarshaler.MarshalOut[TValue](RemoteHandle`1 targetObject, Action action, CallSynchronizationMode syncMode)
at Microsoft.Expression.DesignHost.Isolation.Remoting.ThreadMarshaler.MarshalOut[TResult,TValue](RemoteHandle`1 targetObject, Func`2 func, CallSynchronizationMode syncMode)
at Microsoft.Expression.DesignHost.Isolation.Remoting.LocalDesignerService.CreateDesignerImpl(IHostSourceItem item, IHostTextEditor editor, RemoteCancellationToken remoteCancelToken)
at Microsoft.Expression.DesignHost.Isolation.Remoting.LocalDesignerService.<>c__DisplayClass12.<microsoft.expression.designhost.idesignerservice.createdesigner>b__11(RemoteCancellationToken remoteToken)
at Microsoft.Expression.DesignHost.Isolation.Remoting.LocalDesignerService.CallWithCancellation[TResult](CancellationToken cancelToken, Func`2 func)
at Microsoft.Expression.DesignHost.Isolation.Remoting.LocalDesignerService.Microsoft.Expression.DesignHost.IDesignerService.CreateDesigner(IHostSourceItem item, IHostTextEditor editor, CancellationToken cancelToken)
at Microsoft.Expression.DesignHost.IsolatedDesignerService.IsolatedDesignerView.CreateDesignerViewInfo(CancellationToken cancelToken)
System.ArgumentException
'{DependencyProperty.UnsetValue}' is not a valid value for the 'System.Windows.Controls.Image.Source' property on a Setter.
Server stack trace:
at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.WaitForCompletion(NestedCallContext nestedCallContext, BlockingCall call, WaitHandle timeoutSignal)
at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.MarshalIn(Action action, Int32 targetApartmentId)
at Microsoft.Expression.DesignHost.Isolation.Remoting.ThreadMarshaler.MarshalIn(IRemoteObject targetObject, Action action)
at Microsoft.Expression.DesignHost.Isolation.Remoting.ThreadMarshaler.MarshalIn[TResult](IRemoteObject targetObject, Func`1 func)
at Microsoft.Expression.DesignHost.Isolation.Remoting.RemoteDesignerService.Microsoft.Expression.DesignHost.Isolation.Remoting.IRemoteDesignerService.CreateDesigner(IRemoteHostSourceItem remoteItem, IRemoteHostTextEditor remoteEditor, IRemoteCancellationToken remoteToken)
at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)
Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at Microsoft.Expression.DesignHost.Isolation.Remoting.IRemoteDesignerService.CreateDesigner(IRemoteHostSourceItem remoteItem, IRemoteHostTextEditor remoteEditor, IRemoteCancellationToken cancelToken)
at Microsoft.Expression.DesignHost.Isolation.Remoting.LocalDesignerService.<>c__DisplayClass8.<createdesignerimpl>b__6(IRemoteDesignerService d)
at Microsoft.Expression.DesignHost.Isolation.Remoting.ThreadMarshaler.<>c__DisplayClass4`2.<marshalout>b__3()
at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.Call.InvokeWorker()
System.ArgumentException
'{DependencyProperty.UnsetValue}' is not a valid value for the 'System.Windows.Controls.Image.Source' property on a Setter.
at System.Windows.Setter.Seal()
at System.Windows.SetterBaseCollection.Seal()
at System.Windows.TriggerBase.ProcessSettersCollection(SetterBaseCollection setters)
at System.Windows.Trigger.Seal()
at System.Windows.TriggerCollection.Seal()
at System.Windows.StyleHelper.SealTemplate(FrameworkTemplate frameworkTemplate, Boolean& isSealed, FrameworkElementFactory templateRoot, TriggerCollection triggers, ResourceDictionary resources, HybridDictionary childIndexFromChildID, FrugalStructList`1& childRecordFromChildIndex, FrugalStructList`1& triggerSourceRecordFromChildIndex, FrugalStructList`1& containerDependents, FrugalStructList`1& resourceDependents, ItemStructList`1& eventDependents, HybridDictionary& triggerActions, HybridDictionary& dataTriggerRecordFromBinding, Boolean& hasInstanceValues, EventHandlersStore& eventHandlersStore)
at System.Windows.FrameworkTemplate.Seal()
at System.Windows.FrameworkTemplate.System.Windows.ISealable.Seal()
at System.Windows.StyleHelper.SealIfSealable(Object value)
at System.Windows.ResourceDictionary.SealValue(Object value)
at System.Windows.ResourceDictionary.SealValues()
at System.Windows.ResourceDictionary.AddOwner(DispatcherObject owner)
at System.Windows.ResourceDictionary.PropagateParentOwners(ResourceDictionary mergedDictionary)
at System.Windows.ResourceDictionary.OnMergedDictionariesChanged(Object sender, NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs e)
at System.Collections.ObjectModel.ObservableCollection`1.InsertItem(Int32 index, T item)
at System.Windows.ResourceDictionaryCollection.InsertItem(Int32 index, ResourceDictionary item)
at System.Collections.ObjectModel.Collection`1.Add(T item)
at Microsoft.Expression.DesignSurface.View.WPFSceneView.WpfResourceHost.TrySetApplicationResources()
at Microsoft.Expression.DesignSurface.View.WPFSceneView.WpfResourceHost.EndInstanceBuilding()
at Microsoft.Expression.DesignSurface.View.WPFSceneView.CrossDocumentUpdateToken.System.IDisposable.Dispose()
at Microsoft.Expression.Platform.InstanceBuilders.ViewNodeManager.UpdateInstances(IAttachViewRoot siteRoot, IList`1 contextNodes, CancellationToken cancelToken)
at Microsoft.Expression.DesignSurface.View.XamlSceneView.UpdateInstancesInternal()
at Microsoft.Expression.DesignSurface.View.XamlSceneView.UpdateInternal(Boolean updateInstances, Boolean updateReferences)
at Microsoft.Expression.DesignSurface.View.WPFSceneView.UpdateInternal(Boolean updateInstances, Boolean updateReferences)
at Microsoft.Expression.DesignSurface.View.XamlSceneView.Update(Boolean updateReferences)
at Microsoft.Expression.DesignSurface.View.ViewUpdateManager.UpdateInvalidRelatedDocuments(SceneView view)
at Microsoft.Expression.DesignSurface.View.XamlSceneView.EnsureActiveViewUpdated()
at Microsoft.Expression.DesignSurface.View.WPFSceneView.EnsureActiveViewUpdated()
at Microsoft.Expression.DesignSurface.View.XamlSceneView.SetVisible(Boolean visible)
at Microsoft.Expression.DesignSurface.View.WPFSceneView.SetVisible(Boolean visible)
at Microsoft.Expression.DesignSurface.DocumentViewContext.CreateAndOpenView(ISourceItemContext sourceItem, CancellationToken cancelToken, Boolean activate, Boolean ensureOpenInHost, Boolean suppressUI)
at Microsoft.Expression.DesignSurface.DesignerService.CreateDesigner(IHostSourceItem item, IHostTextEditor editor, CancellationToken cancelToken)
at Microsoft.Expression.DesignHost.Isolation.Remoting.RemoteDesignerService.<>c__DisplayClass10.<>c__DisplayClass12.<microsoft.expression.designhost.isolation.remoting.iremotedesignerservice.createdesigner>b__f(CancellationToken cancelToken)
at Microsoft.Expression.DesignHost.Isolation.Remoting.RemoteDesignerService.CallWithCancellation[TResult](IRemoteCancellationToken remoteToken, Func`2 func)
at Microsoft.Expression.DesignHost.Isolation.Remoting.RemoteDesignerService.<>c__DisplayClass10.<microsoft.expression.designhost.isolation.remoting.iremotedesignerservice.createdesigner>b__e()
at Microsoft.Expression.DesignHost.Isolation.Remoting.ThreadMarshaler.<>c__DisplayClass16`1.<marshalin>b__15()
at Microsoft.Expression.DesignHost.Isolation.Remoting.STAMarshaler.Call.InvokeWorker()
|
|
|
|
|
Build in 3.5 and look at the XAML in the designer; and see if you get the same error. This may not even be a 4.5 problem; on the surface, it looks like there is a problem with the "source" for an "image" (IMO... just a guess... no warranty).
|
|
|
|
|
|