|
Hi Xenon - thanks for the response.
Yes I tried setting the height and width to pixels and I do get a box that will bring up the silverlight menu when you right click inside it, but thats all.
Basically, if the pages that load the sl object are in the root of my project - like the test aspx and html pages added by default when the sl project is created - it works fine.
If I try and load the sl object from a page in a folder (at the same level as ClientBin) It doesn't work. even if I copy the same html or aspx pages directly from the root.
I have to change a couple things -
<param name="source" value="ClientBin/Silverlight Object.xap"/>
becomes
<param name="source" value="..\\ClientBin/Silverlight Object.xap"/> and
<script type="text/javascript" src="Silverlight.js"></script>
becomes
<script type="text/javascript" src="..\\Silverlight.js"></script>
(I don't think the .js is being used, so I don't think I need to do this. If I don't change the ClientBin to ..\\ClientBin, I will get a load error thrown.
Do I need to set mime types or something? I read something about them only being set for the root of the project directory. I am using VS2010.
Thanks!
J
here's the page source I get -
<!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><title>
Silverlight Object
</title>
<style type="text/css">
.style1
{
width: 100%;
}
html, body {
height: 100%;
overflow: auto;
}
body {
padding: 0;
margin: 0;
}
#silverlightControlHost {
height: 500px;
text-align:center;
}
</style>
<script type="text/javascript" src="..\\Silverlight.js"></script>
<script type="text/javascript">
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";
}
alert(errMsg);
throw new Error(errMsg);
}
</script>
</head>
<body>
<form method="post" action="Page1.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJODExMDE5NzY5ZGR3pKj0yol3dSXA8CS0ZrlCCYJQXLMakDaYymKobcWj8w==" />
</div>
<span id="Label1">Not Silverlight</span>
<div id="silverlightControlHost">
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="400px" height="400px">
<param name="source" value="..\\ClientBin/Silverlight Object.xap"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="blue" />
<param name="minRuntimeVersion" value="4.0.50826.0" />
<param name="autoUpgrade" value="true" />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0" style="text-decoration:none">
<img src="http://go.microsoft.com/fwlink/?LinkId=161376" 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>
|
|
|
|
|
- my own stupid mistake.
<param name="source" value="..\\ClientBin/Silverlight Object.xap"/>
should have been -
<param name="source" value="../ClientBin/Silverlight Object.xap"/>
it is working great now
|
|
|
|
|
Hey,
Ive wrote a WPF application and now i wont to give a user the this feature:
1.User will write some DLL that will be based on WPF GUI.
2.When the user will ask my application to load his DLL my APP will load it and present it on the main window then user will work with it.
3.After he will finish to work with it he will ask to unload it.
Question:
1.How it possible to write DLL with WPF GUI?
2.I dont know which DLL's will be so i need to load them dynamicly,how can i do this(maybe user have to implement some inteface in his DLL)?
|
|
|
|
|
To be able to unload dll's you need to load them into a separate ApplicationDomain and when you are done with the dll you need to unload the AppDomain.
//daniel
|
|
|
|
|
I've added xmlns="" to all my XmlDataProvider (after Googling for sometime[^]), but from Visual Studio output Window still getting the very annoying error message - "XmlDataProvider has inline XML that does not explicitly set its XmlNamespace (xmlns="")"
<XmlDataProvider x:Key="MoreColors" XPath="/colors">
<x:XData>
<colors xmlns="" >
<color name="pink"/>
<color name="white"/>
<color name="black"/>
<color name="cyan"/>
<color name="gray"/>
<color name="magenta"/>
</colors>
</x:XData>
</XmlDataProvider>
Any idea? Thanks
dev
|
|
|
|
|
I reproduced your code but it works fine here without any issues. Have you inserted this code inside a resources tag? Eg:
<Grid.Resources>
<XmlDataProvider x:Key="MoreColors" XPath="/colors">
<x:XData>
<colors xmlns="" >
<color name="pink"/>
<color name="white"/>
<color name="black"/>
<color name="cyan"/>
<color name="gray"/>
<color name="magenta"/>
</colors>
</x:XData>
</XmlDataProvider>
</Grid.Resources>
|
|
|
|
|
I almost never use ToString(), but when I do, its for a representation of the entire object. The DataTemplate is binding to a single property (or multiple ones with a value converter).
|
|
|
|
|
DataTemplate is actually often used for the represantation of the entire object, arbitrarily complex (both the object and the representation).
|
|
|
|
|
If I only need to show 1 value in my combobox I normally just set the DisplayMemberPath of the combobox to the property I want to show.
It is said that your life flashes before your eyes just before you die. That is true, it's called Life. - Terry Pratchett
|
|
|
|
|
I would say that ToString "converts" the whole object to a string, simple as that. Which means 1) you can't return any fancy colorful represantation other than a simple string and 2) the ToString() is global application-wise, meaning that you can't make two comboboxes displaying the same list of items make display slightly different things (which you can do with DataTamplates).
DataTemplates are much more versatile, can be specific for a particular control (combobox) or used globally. They can also display much more complex data than just a string.
Then there are value converters...
The call is yours, ToString may be just fine for simple combobox item represatation, setting ItemTemplate doesn't hurt either.
|
|
|
|
|
I wasn't wrong, just not really answering your question, sorry for that. I just wanted to outline the main differences between the two approaches, which is not really what you asked. Ad 1) sure, VM does not return colors, what I had in mind was a rather more complex object than just DisplayName and then ToString() forces you to condense all the data to one string, which can be very limiting and styling is of no help. Ad 2) of course you can use DataTemplates but I was talking about limitations of ToString().
|
|
|
|
|
Not an answer to your question but a comment. You mention Label as a means to display a string, I'll suggest you use TextBlock instead as Label is not much more than a wrapper around TextBlock . Label Only adds the ability to add a border and using an access key, both you can do with out using a Label .
See Josh Smiths discussion about Label and TextBlock Differences between Label and TextBlock[^]
|
|
|
|
|
You may find that this thread[^] covers what's happening and suggests an appropriate solution (the TabControlEx code).
|
|
|
|
|
I want to display a license version in a TextBox from a property and do it with bindings.
There are two buttons to switch between different license versions and a TextBox to display the license version.
Here is the 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">
<StackPanel Orientation="Vertical">
<TextBox Name="txtVersion" Text="????"></TextBox>
<Button Content="Version 1" Click="Version1_Click"></Button>
<Button Content="Version 2" Click="Version2_Click"></Button>
</StackPanel>
</Window>
Notice the TextBox Text property, which I don't know how to bind.
The C# code is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
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;
namespace WpfApplication1
{
public partial class MainWindow : Window, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
License license1;
License license2;
public MainWindow()
{
InitializeComponent();
license1 = new License("Version 1");
license2 = new License("Version 2");
License.Current = license1;
this.DataContext = this;
this.PropertyChanged += new PropertyChangedEventHandler(MainWindow_PropertyChanged);
}
void MainWindow_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
}
private void Version1_Click(object sender, RoutedEventArgs e)
{
License.Current = license1;
PropertyChanged(this, new PropertyChangedEventArgs("Version"));
}
private void Version2_Click(object sender, RoutedEventArgs e)
{
License.Current = license2;
PropertyChanged(this, new PropertyChangedEventArgs("Version"));
}
}
class License
{
static License current;
string version;
public License(string version)
{
this.version = version;
}
public static License Current
{
get { return current; }
set { current = value; }
}
public string Version
{
get { return version; }
}
}
}
The class License has the static instance Current property which always give me access to the current Licence. With this I can access the current version like: License.Current.Version
So how do I bind the TextBox's Text to that?
I try also to display the version number every time I press either of the buttons. Is this a working solution?
|
|
|
|
|
Your binding simply needs to be "{Binding Version}" to bind to the version, providing you add a Version property into your window, e.g.
public string Version { get { return License.Current.Version; } }
|
|
|
|
|
That doesn't work. Crashes with an InvalidOperationException. "A TwoWay or OneWayToSource binding cannot work on the read-only property 'Version' of type 'WpfApplication1.MainWindow'."
I changed the property in the Window and it worked just fine.
public string Version
{
get { return License.Current.Version; }
set { string s = value; }
}
But I'm looking for the WPF binding to reach the Version Property in the License class through the static instance Current of License class. Instead of bind to my Window class.
If it's possible...
|
|
|
|
|
Mc_Topaz wrote: "A TwoWay or OneWayToSource binding cannot work on the read-only property 'Version' of type 'WpfApplication1.MainWindow'."
I changed the property in the Window and it worked just fine.
Wrong fix... Don't put in a dummy setter... Just change the binding to: {Binding Version,Mode=OneWay}
But anyway, you CAN bind to static classes, but you might have trouble with an inner class...
Example:
<TextBlock Text ="{Binding Source={x:Static local:MyStaticClass.MyProperty}}"/>
(From here[^])
|
|
|
|
|
Thanks, I changed the XAML.
But I don't use a static class. I use a static INSTANCE of the same class to reach a property within the class which is not static.
|
|
|
|
|
Hmm, good point... Need more caffeine... So Pete's solution is the best bet, with that OneWay tweak.
|
|
|
|
|
Sorry, I should have mentioned that you would set your binding as Mode=OneWay . As it currently stands, your code cannot do this because License is not a property in your DataContext. This means that while your code-behind can see it, the XAML cannot. To overcome this from your main window, you need to expose a property that can be bound to.
|
|
|
|
|
Allright, that was good to know. Thanks!
|
|
|
|
|
Hi,
I have a Combobox, who gets Gradient blue color when mouse-over or clicked. I managed to change the color of selecting Items background, but the mouse over background color couldn't change.
<Style x:Key="ComboStyle" TargetType="{x:Type ComboBox}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ComboBox}">
<Border Name="bd" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding Background}" Padding="2">
<ContentPresenter />
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="bd" Property="Background" Value="#F7F7F7" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
On adding the above code, MouseOver is definetely achieved i.e. Background color is changed on MouseOver. But with this, I can't see the drop down triagle icon or click the combobox that shows the drop down.
What am I lacking and ho to achieve it ? Any help is highly appreciated.
Thanks & Regards,
|
|
|
|
|
When you set the Template property, you're basically replacing the entire control. In this case, you turned a ComboBox into a ContentControl by removing (not including) all of the things that made it a ComboBox.
If all you want to change is the Background, then you should be putting this stuff directly in the Style.Triggers, not inside a Template.
For example:
<Style TargetType="ComboBox">
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="true">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
|
|
|
|
|
Hi,
I am working on canvas and need to implement infinite scrolling towards the top and bottom.
I have a grid which contains the scrollviewer whose content is the custom canvas. The canvas contains some custom objects which have been drawn over the canvas and bears the drag and drop functionality.
When I drag any object towards right/bottom, scroll bars appear and gives space to put the object.
However, this functionality is not there for top/left scrolling. So, when a object is dragged towards left/top and it reaches the end, the canvas is not resized in order to accomodate the new position of object.
I know, its because canvas has a origin as 0,0 and width and height as infinite.
Currently, user has to 'Select All' all the displayed objects in the canvas and drag towards the right/bottom in order to create a new object towards left/top of it.
Searched and found this link http://www.eggheadcafe.com/software/aspnet/32319058/wpf--scroll-canvas-to-objects-beyon-top-or-left-side.aspx[] of some help, unfortunately unable to mimic the behavior in my application.
Is the use of MeasureOverride() and ArrangeOverride() method is appropriate in this situation?
The best example for infinite scrolling towards right/bottom is Excel sheet. I am looking for the same behavior for left and top.
Please let me know for any clarifications.
Thanks in advance!!!
Praveen
|
|
|
|
|
Hi,
I think the key to solve your problem could be the IScrollInfo interface. Your canvas implementation would override MeasureOverride() to calculate min and max values, ArrangeOverride() to position the items considering the scroll offsets, and implement IScrollInfo to sync the scroll offsets and constraints with the ScrollViewer.
Hope that helps.
|
|
|
|