|
Do you actually need all the direction detail on the binding, I would think the code behind is the datacontext for the UC and a simple binding to the property should suffice. Obviously I have not tried this
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
Silverlight/C# project, I added an image object with a default image, the following code was created
<Image Height="403" HorizontalAlignment="Left" Margin="1212,86,0,0" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="360" Source="/reposMTX;component/Images/09.JPG" />
How can I change the image when a button is clicked?
I tried this
image1.Source = new BitmapImage(new Uri("http://tpsa11/images/shi.bmp", UriKind.RelativeOrAbsolute));
but does not seem to work
|
|
|
|
|
I'm working on a WPF app. The DAL is behind an MVC 4 WebAPI hitting SQL.
I have a one-to-many collection of Addresses & phones. The Address object contains a list of Phone objects. Each address can contain one or many phones.
If I create the phone list using List<phoneentity> then the UI doesn't see new phones when added. If I create the list using ObservableCollection<phoneentity> then when I return the collection from the DAL the phones list is null. The list of phones doesn't serialize coming back from through the API.
What's wrong here? What's the right way to do this?
If it's not broken, fix it until it is
|
|
|
|
|
I would try to add the serialize attribute to the data-model you mentioned. No sense trying to resolve the WPF part until the data-model part is working from your API.
Then I would create a view-model class to separate the data-model class from the WPF window. Add the INotifyProperty pattern to the view-model. And then in xaml, make sure to reference the name of the public properties in your view-model for the collections; like your OC.
Ben Scharbach
Temporalwars.Com
YouTube:Ben Scharbach
|
|
|
|
|
You replied to a message from 3 years ago???
If it's not broken, fix it until it is.
Everything makes sense in someone's mind.
Ya can't fix stupid.
|
|
|
|
|
GUYS how do I generate qr code in wpf?What librarriers needed?thanx in advance
|
|
|
|
|
|
In anpplication I'm working on I would like to display an entire PropertyGrid as an object's toolTip.
XAML 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 Name="grid" >
<Button Background="Yellow" Width="100" Height="100" Name="obj" />
</Grid>
</Window>
C# code:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
System.Windows.Forms.PropertyGrid grid = new System.Windows.Forms.PropertyGrid();
grid.SelectedObject = this;
grid.Width = 200;
grid.Height = 100;
System.Windows.Forms.Integration.WindowsFormsHost host = new System.Windows.Forms.Integration.WindowsFormsHost();
host.Child = grid;
StackPanel panel = new StackPanel();
panel.Children.Add(host);
obj.ToolTip = panel;
}
} Don't forget to reference to System.Sindows.Forms and System.Windows.Forms.Inegration DLL-files.
In the XAML code, notice I use a Button to be the host of the ToolTip. Any recommendation for a better object to host the ToolTip?
I then create the WindowsFormsHost object to host the PropertyGrid. Finally storing the WindowsFormsHost in a StackPanel which I assign to the Button's ToolTip property.
I was not able to assign the WindowsFormsHost to the Button's ToolTip property.
obj.ToolTip = host; // Will Fail
That failed and throwed an ArgumentException when I hovered the mouse curser over the button. With a StackPanel it didn't crash.
When hovering the mouse curser over the button the result is just a white box and the PropertyGrid is not visible
Any suggestions for a solution?
|
|
|
|
|
You can do something else, I don't think such function would be allowed in the ToolTip property.
You can create a seperate function to be called and then show it in the Window on the MouseOver event. Otherwise ToolTip won't allow this.
Favourite line: Throw me to them wolves and close the gate up. I am afraid of what will happen to them wolves - Eminem
~! Firewall !~
|
|
|
|
|
I'm having a problem when loading the png file to image.source. It changes the resolution of png file. The expected is to retain the resolution of png file loaded/rendered on xaml tag.
Thanks,
Jaypee
|
|
|
|
|
Iam trying to configure a service for access over both https and http from a silverlight 4 application. I am able to access the service over https but not over http. I have made some research over the net but can't seem to get the configuration right.
Below is my current settings in the my web.config file.
<system.serviceModel>
<bindings>
<customBinding>
<binding name="MyhttpsBinding">
<binaryMessageEncoding/>
<httpsTransport/>
</binding>
<binding name="MyhttpBinding">
<binaryMessageEncoding/>
<httpTransport/>
</binding>
</customBinding>
</bindings>
<services>
<service name="MyData" behaviorConfiguration="MyData">
<endpoint address="" binding="customBinding" bindingConfiguration="MyData.customBinding.https" contract="MyData"/>
<endpoint address="" binding="customBinding" bindingConfiguration="MyData.customBinding.http" contract="MyData"/>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyData" >
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
</behavior>
<behavior name="">
<serviceMetadata httpsGetEnabled="true" httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
And below is my ServiceReferences.ClientConfig file
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="DataS" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
<binding name="DataS1" maxBufferSize="2147483647" maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</basicHttpBinding>
<customBinding>
<binding name="CustomBinding_GetData">
<binaryMessageEncoding />
<httpsTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" />
</binding>
</customBinding>
</bindings>
<client>
<endpoint address="//localhost/MyApp/Webservice/Data.asmx"
binding="basicHttpBinding" bindingConfiguration="DataS1"
contract="ServiceReference1.DataS" name="DataS" />
<endpoint address="//localhost/MyApp/Webservice/GetData.svc"
binding="customBinding" bindingConfiguration="CustomBinding_GetData"
contract="GetData.GetData" name="CustomBinding_GetData" />
</client>
</system.serviceModel>
</configuration>
What do i have mis-configured above that is making the calls to the service fail on http.
I cannot access the service via http but it works fine over https. And i have a requirement to support both https and http
|
|
|
|
|
Hi All,
Please help on the approach on how will I be able to create an WPF application with requirements below:
- The tool should allow the user to open an image file and draw rectangular areas on top of it that correspond to clickable portions of the image.
- Once the rectangular areas are already placed on top of image, the app will capture the Left, Top positions and Height and Width of rectangular areas.
|
|
|
|
|
I do wonder what your expectations for this message are?
Create a project
add a image control to the main form
add the controls to allow the user to select an image file
place the image on the form
create the controls to begin positioning the rectangles
record the position of the rectangles.
Just like you said!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I have a parent view with its own VM that contains a user control. The control allows the user to enter some data.
The user control's DP's & code are all I the code behind.
In the UC's code behind I created a Validate method that I want to call from the parent view's VM.
How do I do this?
If it's not broken, fix it until it is
|
|
|
|
|
I can think of 2 options, directly wire up the connection between VMs, breaks MVVM separation, ot use a message to fire the UC method.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I'm not happy with either of those approaches. A message doesn't let you return a value
If it's not broken, fix it until it is
|
|
|
|
|
Why does the Validate method have to be in the UC's code-behind? It sounds like it belongs in the VM.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
The user control doesn't have a VM. The code is in the Code Behind
If it's not broken, fix it until it is
|
|
|
|
|
But the main view does have a VM.
And the Validate method is presumably validating one or more properties on that VM.
And you want to call the Validate method from that VM.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
No, I want the VM to call into the UC. The UC is stand alone and should handle all it's own validation so it can be used in multiple places.
So I need to expose a method on it and call it from the parent view's VM.
If it's not broken, fix it until it is
|
|
|
|
|
Well, if you're not going to create a VM for the UC, and you need to return a value from the method, then you're stuck with hooking the method up to the VM somehow.
If you don't want to use the code-behind, then you might be able to get away with binding a delegate. (NB: I haven't tried this.)
UC's code behind:
public ValidationResult Validate() { ... }
public Func<ValidationResult> ValidationMethod
{
get { return Validate; }
}
VM:
public Func<ValidationResult> ValidationMethod { get; set; }
private ValidationResult CallValidation()
{
Func<ValidationResult> fn = ValidationMethod;
if (fn == null) return default(ValidationResult);
return fn();
}
View:
<ns:UserControl
ValidationMethod="{Bind ValidationMethod, Mode=OneWayToSource}"
/>
If the binding doesn't work, then you'll have to hook the method up from the code-behind of the view:
public MyView()
{
InitializeComponent();
DataContextChanged += OnDataContextChanged;
}
private void OnDataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
{
var context = e.NewValue as MyViewViewModel;
if (context != null) context.ValidationMethod = theUserControl.ValidationMethod;
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Well, when do you want to call Validate? Generally, I'd say you'd call a Validate method when you leave the control. If that's the case, you don't need to call it manually, just have the control call it by itself.
|
|
|
|
|
What does 'Leave the control' mean??
The user clicks the 'Save' button on the tab's toolbar. This causes the parent VM's Save method to execute. It then has to call into the UC to save its changes.
Save changes calls Validate before saving.
There is no leaving the control. It's just validate before save.
If it's not broken, fix it until it is
|
|
|
|
|
I meant, "leave the control" as in lose focus. If you want to execute on a Save button, that's a different story. There are a few ways to do it:
1) use a composite command and have the control attach to it
2) use messenger and send a message (p.s. this does not require a VM unless your messenger service is tightly coupled to ViewModelBase which it shouldn't be)
3) get a reference to the view in your viewmodel and reference the control directly
4) use a bindable property to trigger the validation (this is probably the cleanest way). I.e. in your save method:
ValidateControl = true;
the control would need to expose a DP and call Validate() when its set to true, then afterwards reset it to false.
Or, if you don't have control over the control, then an attached property would accomplish the same thing.
|
|
|
|
|
I agree - the DP is probably the cleanest, easiest way to do this.
Many thanks
If it's not broken, fix it until it is
|
|
|
|