|
I think you can get the result same way as you do it with normal xaml file
in CS:
ResourceDictionary skin = new ResourceDictionary();
Instead of
skin.Source = new Uri(@"Themes/ShinyRed.xaml", UriKind.Relative);
Use this
skin.Source = new Uri(@"/ThemeDll;component/ShinyBlue.xaml", UriKind.Relative);
Window win = Window.GetWindow(this);
win.Resources.MergedDictionaries.Clear();
win.Resources.MergedDictionaries.Add(skin);
it works fine for me.
I hope i got your question correctly.
Work relieves us from three great evils, boredom, vice, and want.
|
|
|
|
|
Thanks!
|
|
|
|
|
Well, I have been trying to figure this one out for three days straight and I still haven't come up with a fix.
Basically I am trying to swap out the clicked Ellipse with the only empty spot on the 3x3 checkerboard. 8 of the 9 squares are occupied. I need to find the one spot that is not occupied and I can't seem to do it. Why? Because even though there is an empty spot on the grid at runtime, Javascript refuses to acknowledge this. I used the line: var childrenCount = canvasArray[i].children.count; .. so that's all the canvases. If at runtime there is an empty spot, then how come my code refuses to see it? Or am I not writing the right code? How is the empty spot represented and found at runtime? That's what I want to know.
Here is the pseudocode:
if (squareOnGrid is empty) {
log.write(squareOnGrid + ' is empty');
emptySquare = squareOnGrid;
oldPositionBorder = sender;
oldPositionR = checkerPiece.row;
oldPositionC = checkerPiece.col;
checkerPiece.row = empty.row;
checkerPiece.column = squareOnGrid.column;
oldPositionBorder = null;
}
I want to do this with Javascript (not C#).
I already have this (Javascript):
<br />
function switchPlaces(sender) {<br />
<br />
for (var i = 0; i < canvasArray.length; i++) {<br />
var oldLocationBorderParent = sender;<br />
var oldLocationCanvasParent = oldLocationBorderParent.findName('canvas' + (i + 1));<br />
var oldLocationChild = oldLocationCanvasParent.findName('ellipse' + (i + 1));<br />
<br />
var childrenCount = canvasArray[i].children.count;<br />
log.info(childrenCount);
<br />
if (childrenCount == 0) {<br />
log.info(canvasArray[i] + ' has no children');<br />
var emptySpot = canvasArray[i];<br />
sender['Grid.Row'] = emptySpot['Grid.Row'];<br />
sender['Grid.Column'] = emptySpot['Grid.Column'];<br />
oldLocationCanvasParent.children.remove(oldLocationChild);<br />
}<br />
}<br />
}<br />
Here is my Silverlight code:
<br />
<Grid<br />
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"<br />
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"<br />
Loaded="onLoaded" ShowGridLines="True" Background="CornflowerBlue"><br />
<br />
<Grid.ColumnDefinitions><br />
<ColumnDefinition Width="100"/><br />
<ColumnDefinition Width="100"/><br />
<ColumnDefinition Width="100"/><br />
<ColumnDefinition/><br />
</Grid.ColumnDefinitions><br />
<br />
<Grid.RowDefinitions><br />
<RowDefinition Height="100"/><br />
<RowDefinition Height="100"/><br />
<RowDefinition Height="100"/><br />
</Grid.RowDefinitions><br />
<br />
<Border Grid.Row="0" Grid.Column="0" x:Name="b1" MouseLeftButtonUp="switchPlaces" ><br />
<Canvas x:Name="canvas1"><br />
<Ellipse Width="100" Height="100" x:Name="ellipse1" Fill="Red" Visibility="Visible"/><br />
</Canvas><br />
</Border><br />
<br />
<Border Grid.Column="0" Grid.Row="1" x:Name="b2" MouseLeftButtonUp="switchPlaces" ><br />
<Canvas x:Name="canvas2"><br />
<Ellipse Width="100" Height="100" x:Name="ellipse2" Visibility="Visible"/><br />
</Canvas><br />
</Border><br />
<br />
<Border Grid.Column="0" Grid.Row="2" x:Name="b3" MouseLeftButtonUp="switchPlaces" ><br />
<Canvas x:Name="canvas3"><br />
<Ellipse Width="100" Height="100" x:Name="ellipse3" Visibility="Visible"/><br />
</Canvas><br />
</Border><br />
<br />
<Border Grid.Column="1" Grid.Row="1" x:Name="b4" MouseLeftButtonUp="switchPlaces" ><br />
<Canvas x:Name="canvas4"><br />
<Ellipse Width="100" Height="100" x:Name="ellipse4" Visibility="Visible"/><br />
</Canvas><br />
</Border><br />
<br />
<Border Grid.Column="1" Grid.Row="2" x:Name="b5" MouseLeftButtonUp="switchPlaces" ><br />
<Canvas x:Name="canvas5"><br />
<Ellipse Width="100" Height="100" x:Name="ellipse5" Visibility="Visible"/><br />
</Canvas><br />
</Border><br />
<br />
<Border Grid.Column="2" Grid.Row="0" x:Name="b6" MouseLeftButtonUp="switchPlaces" ><br />
<Canvas x:Name="canvas6"><br />
<Ellipse Width="100" Height="100" x:Name="ellipse6" Visibility="Visible"/><br />
</Canvas><br />
</Border><br />
<br />
<Border Grid.Column="2" Grid.Row="1" x:Name="b7" MouseLeftButtonUp="switchPlaces" ><br />
<Canvas x:Name="canvas7"><br />
<Ellipse Width="100" Height="100" x:Name="ellipse7" Visibility="Visible"/><br />
</Canvas><br />
</Border><br />
<br />
<Border Grid.Column="2" Grid.Row="2" x:Name="b8" MouseLeftButtonUp="switchPlaces" ><br />
<Canvas x:Name="canvas8"><br />
<Ellipse Width="100" Height="100" x:Name="ellipse8" Visibility="Visible"/><br />
</Canvas><br />
</Border><br />
<br />
</Grid><br />
If anyone has any idea how to fix this..
Thank you
|
|
|
|
|
I must be missing something here...
What is this canvas array and how does it relate to the Silverlight Grid?
How does the managed Silverlight code know about the canvas array?
How are you calling javascript from managed code?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi,
my question is, how do I sort related items of an entity.
In an invoice editing window, I have one ComboBox displaying all customers:
XAML:
<UserControl.Resources>
<CollectionViewSource x:Key="cvsCustomers"
d:DesignSource="{d:DesignInstance local:Customer, CreateList=True}" />
...
</UserControl.Resources>
<ComboBox ItemsSource="{Binding Source={StaticResource cvsCustomers}}" .../>
Code-behind:
Dim cvsCustomers As System.Windows.Data.CollectionViewSource
cvsCustomers = CType(Me.FindResource("cvsCustomers"), System.Windows.Data.CollectionViewSource)
Dim qryCustomers = _
From c In myEntities.Customers _
Order By c.CustomerCode
Select c
cvsCustomers.Source = qryCustomers
Now I have a 2nd ComboBox displaying all contact persons of the selected customer. This works fine, but the entries in this second ComboBox are unsorted / sorted by ID.
XAML:
<ComboBox ItemsSource="{Binding Path=myInvoice.Customer.Contacts}" .../> ;
How do I get the list on the 2nd ComboBox sorted?
King regards,
and thanks in advance for tips/suggestions,
Nico
|
|
|
|
|
Hey,
I've been optimising a piece of software with a very large number of simple controls (~30000), most of whom have their parent panel virtualised at any one time (reducing the number in the visual tree to a few hundred). Running through ANTS profiler, I'm told that 60-70% of CPU-time is taken up by UIElement_CreateAutomationPeerDelegate.Invoke and its child methods. A user interacting with the program for 20 seconds or so [creating an additional ~20 of these controls, deleting a few, and moving a few around the page] results in this method being called 5.4 million times. Putting a counter near this method confirms this when run without debugging/ANTS.
As far as I'm aware, I haven't touched AutomationPeer-related methods, and it is used for Accessibility/COM stuff. Can I turn this 'function' off, or are there ways of reducing how many times it is called?
TIA,
Lee
|
|
|
|
|
At the risk of getting 1'ed, I'd say you are trying to band aid things here. Fix the real issue. You shouldn't need 30,000 controls in a single window .
-- Modified Monday, July 18, 2011 7:04 PM
|
|
|
|
|
Haha, well agreed to an extent. The maximum number of controls 'on' the window at any one time is actually around 200 (and usually only around 40) - the rest are held in memory waiting to be connected to the visual tree when scrolling takes place.
I have tried virtualising these 'properly' so that they are re-used but the overhead for them binding to their data is actually more costly than having them just sit in memory (which I certainly found surprising)
|
|
|
|
|
Hi,
is their any timepicker control available in wpf with vb.net?
|
|
|
|
|
|
|
I am looking for a way where a control can be enable when an item from a combo box is selected. Is there a simple way through data binding when a user selects an item from a combo box that it then enables another control to be used?
|
|
|
|
|
One way is to bind IsEnabled on the control(s) to the ComboBox SelectedIndex or SelectedItem property using a value converter[^] on the binding to convert the Selectedxxx value to a bool.
[System.Windows.Data.ValueConversion(typeof(int), typeof(bool))]
public class SelectedIndexToIsEnabledConverter : System.Windows.Data.IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return ((int)value >= 0) ? true : false;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
throw new System.NotImplementedException();
}
}
<UserControl.Resources >
<local:SelectedIndexToIsEnabledConverter x:Key="SelectedIndexToIsEnabledConverter" />
</UserControl.Resources>
...
Example binding:
IsEnabled="{Binding Path=SelectedIndex,ElementName=comboBox1,Converter={StaticResource SelectedIndexToIsEnabledConverter},Mode=OneWay}"
Mark Salsbery
Microsoft MVP - Visual C++
modified on Friday, July 15, 2011 12:33 PM
|
|
|
|
|
Hello,
Could someone help me out here please.. I have a game algorithm problem: http://oi56.tinypic.com/29x6op0.jpg
Thank you
|
|
|
|
|
Please post on the algorithm board[^] if you want algorithms.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Wrong forum.
Too much of heaven can bring you underground
Heaven can always turn around
Too much of heaven, our life is all hell bound
Heaven, the kill that makes no sound
|
|
|
|
|
Not wrong forum. The people from the algorithm forum sent me here.
|
|
|
|
|
And yet you say you have a problem with an algorithm, ergo it's an algorithm forum post.
|
|
|
|
|
A game algorithm in a Silverlight app.
|
|
|
|
|
Hello All,
I have issue with WCF ASYNC call. WCF service give me a random response. Sometimes it gives me result and sometimes not. I have set max values for binding related properties.
Can anyone can help me to figure out this issue?
Thanks
|
|
|
|
|
This could be something to do with the timeout or buffer size.
Try changing these settings.
Too much of heaven can bring you underground
Heaven can always turn around
Too much of heaven, our life is all hell bound
Heaven, the kill that makes no sound
|
|
|
|
|
Hi,
I wouold like to learn a little about how to design better UI in silverlight or WPF in visual studio.
1-
Is there a book to teach me that in visual studio xaml or should I buy a step by step book in expressin blend? I say expression blend because it seems that I can use the code in expression blend and paste the xaml into visual studio.
Thank you
|
|
|
|
|
I don't know a book to recommend, but you don't need to paste code into visual studio. Expression Blend works with Visual Studio solutions/projects so you can edit (and run) code in Blend and edit and debug in Visual Studio as well.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
To learn better design, Expression Blend would be a better bet than Visual Studio.
As already pointed out, you can edit xaml in Expression Blend as well.
Too much of heaven can bring you underground
Heaven can always turn around
Too much of heaven, our life is all hell bound
Heaven, the kill that makes no sound
|
|
|
|
|
Yes "Good Answer". You can use Expression Blend to create the UI styles very easily which is very very difficult if you are using Visual Studio to design. Visual Studio requires depth knowledge on XAML. Also more effort is require if you are designing using the VS. Use Expression Blend which will help you a lot.
Silverlight 5 Tutorials : 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
|
|
|
|