|
Style looks like this:
<style x:key="ButtonStyle" targettype="{x:Type Button}" xmlns:x="#unknown">
<setter property="Template">
<setter.value>
<controltemplate targettype="{x:Type Button}">
<controltemplate.resources>
<!-- Storyboards go here -->
</controltemplate.resources>
<grid>
<!-- Content goes here -->
</grid>
<controltemplate.triggers>
<!-- Triggers go here -->
</controltemplate.triggers>
</controltemplate>
</setter.value>
</setter>
</style>
You have to put everything in the appropriate place for it to work, then apply the style to the element you want
|
|
|
|
|
Thanks for reply! Is it possible to do that without defining a template? I believe that a simple style with 2 triggers would be enough
|
|
|
|
|
Yes. I think you can just ignore the "template" setter.. so just erase the <Setter Property="Template> and the <Setter.Value> stuff all the way until the </Setter> tag. I think you can just put a <Style.Resources> tag and put all the triggers in there... I think.... I haven't actually made any sample of this, but if that doesn't work I can always try to find a solution instead of doing my job lol
|
|
|
|
|
I thought the same and tried it, but it didn`t work. I got an error like I wrote in first post.
|
|
|
|
|
You can do
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="{DynamicResource GenericButtonFontBrush}"/>
</Trigger>
</Style.Triggers>
|
|
|
|
|
Hello, I need to change content of Window2 in time. I use event to inform Window2 to change content and thread evoking event. To be easy, I only change content of Label in Window2 in time. Problem is, that content of Label isn´t changing when is thread sleeping and Windows "are not responding" and I don´t see anything in Windows 2. I see Label in Window2 only when my thread ends. I need to see Label with content "1", and in several seconds with content "2".... Could someone please have a look at my code and help me what I´m doing wrong?
App.xaml
<application x:class="WpfApplication1testtemplate.App" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="Window1.xaml">
<application.resources>
</application.resources>
</application>
Window1.xaml
<window x:class="WpfApplication1testtemplate.Window1" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<grid>
<button height="23" horizontalalignment="Right" margin="0,105,27,0" name="button1" verticalalignment="Top" width="75" click="button1_Click">Start</button>
</grid>
</window>
Window1.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
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.Windows.Threading;
namespace WpfApplication1testtemplate
{
internal delegate void QueueListenerDelegate(Queue queue, MyArgumet args);
partial class Window1 : Window
{
Window2 w2;
public Window1()
{
InitializeComponent();
w2 = new Window2();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
w2.Show();
Thread t = new Thread(new ThreadStart(Run));
t.SetApartmentState(ApartmentState.STA);
t.Start();
}
void Run()
{
this.Dispatcher.BeginInvoke(
DispatcherPriority.Send, (ThreadStart)delegate {
Queue queue = new Queue();
queue.NewItemAdded += new QueueListenerDelegate(w2.ListenAdd);
Random rand = new Random();
int d = 0;
queue.Add(d.ToString());
Thread.Sleep(2000);
d = 1;
queue.Add(d.ToString());
Thread.Sleep(2000);
d = 2;
queue.Add(d.ToString());
Thread.Sleep(2000);
queue.Add(d.ToString());
Thread.Sleep(2000);
d = 3;
queue.Add(d.ToString());
});
}}}
Window2.xaml
<window x:class="WpfApplication1testtemplate.Window2" xmlns:x="#unknown">
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window2" Height="300" Width="300">
<grid>
<dockpanel name="dockPanel1" />
</grid>
</window>
Window2.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
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.Shapes;
namespace WpfApplication1testtemplate
{
partial class Window2 : Window
{
public Window2()
{
InitializeComponent();
myLabel = new Label();
}
public Label myLabel;
public int i = 0;
internal void ListenAdd(Queue queue, MyArgumet args)
{
if (i != 0) dockPanel1.Children.Remove(myLabel);
myLabel.Content = (String)args.AddedObject;
dockPanel1.Children.Add(myLabel);
i++;
}}}
Queue.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WpfApplication1testtemplate
{
class Queue
{
public event QueueListenerDelegate NewItemAdded;
public Queue()
{
}
public void Add(string o)
{
if (NewItemAdded != null) NewItemAdded(this, new MyArgumet(o));
}}}
MyArgumet.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WpfApplication1testtemplate
{
class MyArgumet : EventArgs
{
private object addedObject;
public object AddedObject
{
get { return addedObject; }
set { addedObject = value; }
}
public MyArgumet(object addedObject)
{
this.addedObject = addedObject;
}}}
|
|
|
|
|
Is there a reason that your architecture is so complicated? I can't see a lot of the code off to the side because of formatting issues here, but I can't see any reason why you need your code to be as complicated. Why not use an ObservableCollection if you need a collection of "changes"? If it's just updating a simple binding, take a look at using the DispatcherTimer.
Here's a simple object that uses the DispatcherTimer to update the time every second:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Windows.Threading;
using System.Windows;
namespace MyNamespace
{
public class TimeManager : INotifyPropertyChanged, IDisposable
{
private DispatcherTimer _timer = null;
private string _currentDateAndTime;
public TimeManager(Window parent)
{
_timer = new DispatcherTimer(TimeSpan.FromSeconds(1), DispatcherPriority.Normal, new EventHandler(TimerTick), parent.Dispatcher);
}
protected virtual void TimerTick(object sender, EventArgs e)
{
CurrentDateAndTime = DateTime.Now.ToString();
}
protected virtual void Changed(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName));
}
}
public string CurrentDateAndTime
{
get
{
return _currentDateAndTime;
}
set
{
if (_currentDateAndTime != value)
{
_currentDateAndTime = value;
Changed("CurrentDateAndTime");
}
}
}
#region INotifyPropertyChanged Members
public event PropertyChangedEventHandler PropertyChanged;
#endregion
internal void Start()
{
if (_timer != null)
_timer.Start();
}
private void Stop()
{
if (_timer != null)
_timer.Stop();
}
#region IDisposable Members
public void Dispose()
{
Dispose(true);
}
private bool _disposed = false;
protected virtual void Dispose(bool dispose)
{
if (!_disposed && dispose)
{
Stop();
_disposed = true;
GC.SuppressFinalize(this);
}
}
#endregion
}
} Here's a status bar (UserControl) that makes use of it:
using System;
using System.Collections.Generic;
using System.Linq;
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;
namespace MyNamespace
{
public partial class StatusBar : UserControl
{
private TimeManager _timeManager = null;
public StatusBar()
{
InitializeComponent();
}
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
DependencyObject parent = this.Parent;
while (parent != null && !(parent is Window))
parent = LogicalTreeHelper.GetParent(parent);
if (parent != null)
{
_timeManager = new TimeManager(parent as Window);
TimePortion.DataContext = _timeManager;
_timeManager.Start();
}
}
private void UserControl_Unloaded(object sender, RoutedEventArgs e)
{
if (_timeManager != null)
{
_timeManager.Dispose();
}
}
}
}
|
|
|
|
|
I´m only a student And I didn´t have better idea and I´m beginner in WPF I have a look at your code. Thank you very much
|
|
|
|
|
No problem. Glad to help.
|
|
|
|
|
I have modified the CellTemplate of a ListView with a custom control called EditBox which allows the user to edit the data in the ListView. The EditBox-class actually has a BeginEdit() function which I want to call, but how can I access the EditBox-instance?
|
|
|
|
|
I covered this in this blog[^] example. You may find it useful.
|
|
|
|
|
Hi
I've wanted to create a simple 3D App in WPF, so i wanna to know we can import 3DMax's models ( *.max files) in Expression Blend ?
If so , how can we do it ?
Many thanks in advance
|
|
|
|
|
I believe the .Max format is protected so it won't be possible to use .max files directly. Instead you might use .3DS. You may even consider importing the 3DS into Blend which can export to Xaml.
I don't know it there are Xaml exporters at the moment. But it should be too hard to write a simple exporter using MaxScript.
Dawn is nature's way of telling you to go to bed.
|
|
|
|
|
You can export 3DS files out to XAML using this[^]. I've not tried it, because I prefer working in Maya and Cinema4D, but it should do the job; and do let us know if it does won't you?
|
|
|
|
|
Thanks Pete.
It's worked.
|
|
|
|
|
Excellent news. That's one for the toolkit then.
|
|
|
|
|
|
I have 2 silverlight controls in a aspx page. Control A fires a static event, and Control B listens to it. Since they are in different DLLs, i've added a reference from Control A into B.
Sadly, B never hears the event, i know its being fired as i've added some debug messages.
Does silverlight not allow this type of functionality ? or am i going about it the wrong way?
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
I think the only way you could make that work, would be to have both of them communicate with their parent container and let the parent be the go-between.
If you look at the test web page that VS2008 generates, there's some javascript in there that might give you a clue how to go about it:
function onSilverlightError(sender, args) {<br />
<br />
var appSource = "";<br />
if (sender != null && sender != 0) {<br />
appSource = sender.getHost().Source;<br />
} <br />
var errorType = args.ErrorType;<br />
var iErrorCode = args.ErrorCode;<br />
...<br />
...
You could maybe pass a custom function to your Silverlight objects as a parameter the same way the error handler is passed:
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%"><br />
<param name="source" value="ClientBin/SilverlightApplication2.xap"/><br />
<param name="onerror" value="onSilverlightError" /><br />
<param name="background" value="white" /><br />
<param name="minRuntimeVersion" value="2.0.31005.0" /><br />
<param name="autoUpgrade" value="true" /><br />
<a href="http://go.microsoft.com/fwlink/?LinkID=124807" style="text-decoration: none;"><br />
<img src="http://go.microsoft.com/fwlink/?LinkId=108181" alt="Get Microsoft Silverlight" style="border-style: none"/><br />
</a><br />
</object>
It's just a thought...don't know if it'd work or not
Update: I don't think my above suggestion will work. I found an interesting video on InitParams here[^] though.
Update2: Oh yes you can do it. Here's a video[^] that tells how
modified on Sunday, October 26, 2008 1:10 PM
|
|
|
|
|
Hi,
I am a beginner to silverlight.i would like to know what are the installers to get silverlight effects.
I installed Microsoft Silverlight1.1 Tools Alpha for Visual Studio 2008 and Microsoft Silverlighr1.1 Alpha Refresh. And i opened new silverlight scriptweb and created new aspx page.when i run that application i didn't get any changes according to silverlight. And there is a silverlight.js file by default.what is the use of that file and how to use that file.Please help me how to solve my silverlight problem.
Thanks
pavani
|
|
|
|
|
Has anyone been able to get an SL app successfully communicating with a self-hosted WCF service? My SL app complains about a badly configured ClientAccessPolicy.xml file, but according to every article and post I've read, I'm doing the right thing. Web Development Helper confirms my SL app successfuly accesses the file (whose headers and content are A-OK). I'm also able to manually browse the ClientAccessPolicy.xml file with no problems and communicate with the service using non-SL apps just fine. (The service itself is a trivial one.)
Thanks for any light you can shed on a solution. (Sorry, hosting the service in IIS isn't a solution ).
Thanks,
/ravi
|
|
|
|
|
Ravi - answering questions with questions here I'm afraid. What do you mean by self-hosted?
|
|
|
|
|
I mean the WCF service runs in a Windows service or console/WinForms app using an instance of a ServiceHost class, instead of running as a .svc in IIS. Thanks for any help you can provide!
/ravi
|
|
|
|
|
Figured it out - CP article coming soon.
/ravi
|
|
|
|
|
Ravi
I suspect you may have the key to my problem as well. I'm running a C# .NET web service under IIS with an accessible ClientAccessPolicy file too. I can call the service from an SL2 app running on the same machine and another machine running on the same intranet but not from an apparently different domain.
Thoughts?
|
|
|
|