|
Yes and yes.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
I am looking for a variation of this answer as well (assuming I read the question right).
I have a simple UserControl that has 3 controls which I plan to use to standardise the visual look. The only part of this control that will very is the text on the button. I would like to be able to set this within the XAML as once set it will not change.
For example, i would like to be able to do something like this.
<Views:CurrentStatusView ButtonText="Proceed"/>
If I expose a property I am able to set the value, but how do I use this within the user control, I have tried Binding, setting the value in the constructor etc with no success.
Many thanks
Just racking up the postings
modified on Thursday, September 3, 2009 10:26 AM
|
|
|
|
|
Here's a sample that shows how to do this (first of all, the XAML):
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="WpfSample.CurrentStatusView"
x:Name="UserControl"
d:DesignWidth="640" d:DesignHeight="480">
<Grid x:Name="LayoutRoot">
<Button HorizontalAlignment="Left" VerticalAlignment="Top" Content="{Binding ButtonText}"/>
</Grid>
</UserControl> then the code behind
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.ComponentModel;
namespace WpfSample
{
public partial class CurrentStatusView : UserControl
{
public CurrentStatusView()
{
this.InitializeComponent();
ButtonText = "Hello there";
DataContext = this;
}
public static DependencyProperty ButtonTextProperty =
DependencyProperty.Register(
"ButtonText",
typeof(string),
typeof(CurrentStatusView));
public string ButtonText
{
get { return GetValue(ButtonTextProperty).ToString(); }
set { SetValue(ButtonTextProperty, value); }
}
}
} Finally, you set it with:
<WpfSample:CurrentStatusView ButtonText="Howdy" HorizontalAlignment="Left" Margin="27,42,0,0" VerticalAlignment="Top" />
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
|
Obviously you are trying to swallow more than you can chew.
You really do need to spend a minimum time learning the little tiny block of which a WPF application is made.
Stress to your boss that you need a learning phase (such as 1 week reading CP articles and experimenting) and it's not wasted as you are just unable to be productive yet!
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
The answer to this question will also answer a more general question I've had that I haven't been able to figure out. The more general question is, how do I address a WPF object in my assembly from a Uri object? This would be so useful but I've never been able to figure out how to do it. So answer the specific question and a whole new world will open up for me. I think the answer is going to involve some use of the UriKind.Relative value as the second parameter in the Uri constructor but I don't know how to express the first parameter in the constructor.
Say I have a Window object in my assembly called TextWindow. I want to pop up TextWindow by clicking on a WPF Hyperlink object within a Paragraph. What would the XAML look like? Something like:
<Paragraph>
<Hyperlink
NavigateUri="???TextWindow???"
>
My Hyperlink Title
</Hyperlink>
</Paragraph>
What would I replace the "???" strings with to make this work? I know it's easy to do stuff like this in WPF, but I'm surely not very good at reading the documentation to find the answer.
|
|
|
|
|
I guess the lack of response stemmed from the incoherence of my question. It was based on a misunderstanding of what Hyperlink.NavigateUri is all about. It does not apply to the Window class but to the Page class. Also, in my application, it is more appropriate to place the Hyperlink object inside of a TextBlock, not a Paragraph. So my XAML ended up looking like this:
<TextBlock
Margin="0,5,0,0"
>
<Hyperlink NavigateUri="TutorialOverviewOfPhotoShowsPage.xaml">
Overview of Photo Shows
</Hyperlink>
</TextBlock>
Sometimes it helps to ask a question in a forum because it forces you to articulate the problem. Even if your articulation isn't entirely coherent, it gets you thinking more deeply about the problem you are trying to solve. I hope I didn't offend anyone by cluttering up the forum with a question that did not make any sense.
However, I'm not sure I learned how to code my larger issue. I don't think I stated that coherently, either.
|
|
|
|
|
I've a webservice that returns a TList object and populates the datagrid as follow:
void proxy_CustomerInfoCompleted(object sender, CustomerInfo.CustomerInfoCompletedEventArgs e)
{
datagrid1.ItemsSource = e.Result;
}
It works, but now, what I need to do is to create a local TList copy of the e.result and then bind the newly created object to the datagrid. Is it possible to do it in C#?
Something like:
TList<Customer> = e.Result;
datagrid1.ItemsSource = Customer;
|
|
|
|
|
What is a TList?
e.Result is apparently already a reference to "a local TList copy"
so can't you just assign it to a variable?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
That is my point exactly!
e.Result is the object that is returned from the Web Service. It is a TList object. But how do I copy it to a local TList object?
|
|
|
|
|
TList mytlist = e.Result as TList;
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Correcting the subject: The e.Result is a List collection and not a TList object as mentioned before.
I need to know how to copy it to another List collection.
I've attempted in a variety of ways but always endup with a compiler error that doesn't accept the e.Result as a valid List
modified on Tuesday, September 1, 2009 6:59 PM
|
|
|
|
|
Have you tried the following?
TList list = new TList();
list.AddRange(e.Result);
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Your e.Result will most likely be a collection object that inherits from ICollection.
From the threads it looks like it is a List<customer>. If it is then you can simply use
List<Customer> myObjectName = (List<Customer>)e.Result;
Otherwise if you really want to make a copy of the list use LINQ[^]
"A democracy is nothing more than mob rule, where fifty-one percent of the people may take away the rights of the other forty-nine." - Thomas Jefferson
"Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote." - Benjamin Franklin
Edbert
Sydney, Australia
|
|
|
|
|
"Your e.Result will most likely be a collection object that inherits from ICollection."
You are right and by watching the compiler error I can see it is from "System.Collections.Generic.IEnumerable" and the List is from "System.Collections.Generic.List" thus the problem.
I've changed the Service Configuration to return a List instead of a collection but it didn't help. The only way to create a local copy of the list returned by the web server was doing the folllowing:
for (int i = 0; i < e.Result.Count; i++)
{
myClass.Add(new myClass()
{
AcctNo = e.Result[ i ].AcctNo,
Name = e.Result[ i ].Name,
Address = e.Result[ i ].Address,
Phone = e.Result[ i ].Phone,
EMail = e.Result[ i ].EMail
});
}
|
|
|
|
|
Since this is Silverlight, when you generate the WCF service reference you can actually select whether you want the web service to use existing class structure in its service definition instead of System.Collections.Generic.List.
To do this right-click on your service reference in the Silverlight project, choose "Configure Service Reference" and on the panel tick on "Reuse types in all referenced assemblies", or if you have a specific assembly pick the specific assembly containing the class definition.
If you do the above the e.Result should be of type ObservableCollection<customer> instead of a generic list.
Hope that helps.
Edbert
Sydney, Australia
|
|
|
|
|
Hello All,
I am working on WPF application with MVP architecture. My question is :
how to get the name of the selected node in a tree? Also, i need to get the name of the parent node that the selected node belongs to.
Node1
A1
A2
A3
A4
Node2
A1
A2
A5
A8
Node3
A1
A2
A9
Asin the treeview, it has 3 nodes and each node having children. If I select the Child A2, from Node3, how can this be stored in a string? and also I should get the parent of this A2(which is Node3).
So, on selection of A2 in Node3, I should have the names of A2 and its parent node.
I am doing it in C#.
Please help me.
Thank You,
Ramm
|
|
|
|
|
You probably need to check the events raised by TreeView. I would expect that a click or select event of some form is raised when the user clicks a node, and the code behind should be able to capture that event, which will likely have a reference to the selected node. Each node in the tree has a parent property that can be used to traverse the tree to its main root. Try a search for TreeView in MSDN and look at the Properties and Events.
|
|
|
|
|
Hi,
I am working on a silverlight project. In this when I try to publish my code It failed and it didn't gave me any error. So I took the old application for which publish is successfull and modified it with the changes in the code. Now the .xap file is now updating my chages and it is displaying the old functionality.
If anyone have any idea to make the publish successfull or update the .xap file , please reply me.
Thanks in advance.
|
|
|
|
|
The old XAP file probably lingers on somewhere in a cache. You could try to rename the XAP file, or add a random number in the source parameter of the object tag like
<param name="source" value="XapFile.xap?12345"/><br />
|
|
|
|
|
 OK, here's an extended version. This code appends the file date/time to the XAP file name. This way you'll keep the caching of already loaded XAP files and you don't have to remember to change the number...
<%@ Page Language="C#" AutoEventWireup="true" %>
<script runat="server">
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
const string XAP = "ClientBin/XapFile.xap";
System.IO.FileInfo fi = new System.IO.FileInfo(Request.MapPath("./" + XAP));
string timeStampXAP = fi.LastWriteTime.ToString("yyyyMMdd_HHmmss");
source.Text = String.Format("<param name=\"source\" value=\"{0}?{1}\" />", XAP, timeStampXAP);
}
</script>
<%@ OutputCache Duration="1" VaryByParam="None" Location="None" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Test</title>
<style type="text/css">
html, body {
height: 100%;
overflow: auto;
}
body {
padding: 0;
margin: 0;
}
form {
height: 100%;
}
#host {
height: 100%;
text-align:center;
}
</style>
<script type="text/javascript" src="Silverlight.js"></script>
<script type="text/javascript">
window.onload = function()
{
document.getElementById('host').focus();
}
function onSilverlightError(sender, args) {
var appSource = "";
if (sender != null && sender != 0) {
appSource = sender.getHost().Source;
}
var errorType = args.ErrorType;
var iErrorCode = args.ErrorCode;
if (errorType == "ImageError" || errorType == "MediaError") {
return;
}
var errMsg = "Unhandled Error in Silverlight Application " + appSource + "\n";
errMsg += "Code: " + iErrorCode + " \n";
errMsg += "Category: " + errorType + " \n";
errMsg += "Message: " + args.ErrorMessage + " \n";
if (errorType == "ParserError") {
errMsg += "File: " + args.xamlFile + " \n";
errMsg += "Line: " + args.lineNumber + " \n";
errMsg += "Position: " + args.charPosition + " \n";
}
else if (errorType == "RuntimeError") {
if (args.lineNumber != 0) {
errMsg += "Line: " + args.lineNumber + " \n";
errMsg += "Position: " + args.charPosition + " \n";
}
errMsg += "MethodName: " + args.methodName + " \n";
}
throw new Error(errMsg);
}
</script>
</head>
<body>
<form id="form1" runat="server" enableviewstate="false">
<div id="host">
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<asp:Literal ID="source" runat="server" />
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="3.0.40624.0" />
<param name="autoUpgrade" value="true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=3.0.40624.0" style="text-decoration:none">
<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style:none"/>
</a>
</object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
</form>
</body>
</html>
|
|
|
|
|
Hi.
A nice idea. But it did not work for me. I use the divelement tools where I can display HTML content. And the content of this divelement controls stopps working by using your methode and does a refresh of the whole page.
|
|
|
|
|
I don't know if zlezj's solution is necessary, but...
During development I've noticed sometimes the browser will use a cached xap
instead of my freshly changed xap, so I just got in the habit of clearing the browser
cache every time I test.
Also make sure your newer xap files are actually overwriting old ones when you
publish.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Is there a simple way to set the IsChecked state of a CheckBox without invoking any Checked event handlers? I want to set the initial state of a checkbox without invoking the Checked handler unnecessarily.
I know it's as simple as having a flag that the event handler looks at, or unhooking the event handler while I'm initializing the check box state, but that just seems clumsy.
Software Zen: delete this;
|
|
|
|
|
How about:
<CheckBox Content="I'm Checked!" IsChecked="True"/>
or, in code:
theCheckbox.IsChecked = true;
Now, I'm a bit puzzle by what you mean "in the event handler"
You don't set it in the event handler (that would be pointless and against the normal behavior of a checkbox), you get the new value!
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
modified on Monday, August 31, 2009 9:00 PM
|
|
|
|