|
The simple option would seem to be:
- In project #2, add a reference to project #3;
- Define styles in project #2 for the controls in project #3, in exactly the same way you define styles for the built-in controls;
You'll probably want to use the XmlNsPrefix and XmlNsDefinition attributes in project #3 to make it easier to import the control's namespace:
A Guide to Cleaner XAML with Custom Namespaces and Prefixes (WPF/Silverlight)[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Project 2 is the Desktop Theme & Images project. You're saying add a ref to the User Control library??
Not sure about that. That won't work.
If it's not broken, fix it until it is
|
|
|
|
|
You can't define styles for an unknown control. The project that defines the styles for #3 must have a reference to #3.
If you can't do that in #2, then you'll need to do it in a new project.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
If you bought a set of controls, such as Telerik, and used them in 3 different projects, each of those projects can have a different look and feel.
- So how does the app tell the control what style to use? The Telerik assembly doesn't know about your app.
- How do you tell specific controls in that library what to look like. It's not enough to set the TargetType because that will set ALL controls of that type. You would need a way to say "For this specific combobox, make it look like this".
This HAs to be possible. They're doing it.
If it's not broken, fix it until it is
|
|
|
|
|
You would define styles which applied to the specific controls. If you didn't want the style to apply to all instances of the same control, you would give it a name.
You would still need to have a reference from the project where the styles were defined to the project / assembly where the controls were defined.
You can't define a style for a control that your project doesn't know about!
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
If in the User Control library I created a reference to the app, that makes that User Control library bound forever to that one app.
The other way around is how it's used. The app know about the UC library, not the UC library knowing about the app.
The TimePicker has a TextBlock and 3 ComboBoxes. There has to be a way in the form it's on to say "Set the combo boxes to use TimerPickerComboStyle" without the entire UC assembly having a ref to the App project.
If it's not broken, fix it until it is
|
|
|
|
|
Kevin Marois wrote: If in the User Control library I created a reference to the app, that makes that User Control library bound forever to that one app.
I'm not talking about the UC project having a reference to the application. I'm talking about the "shared styles" project having a reference to the UC project.
The "shared styles" project is the one that's defining the styles for the controls in the UC project, so that's the one that needs a reference to the UC project.
Kevin Marois wrote: There has to be a way in the form it's on to say "Set the combo boxes to use TimerPickerComboStyle" ...
You could expose a dependency property typed as Style , and bind that to the child control's Style property in the OnApplyTemplate method.
public static readonly DependencyProperty ComboBoxStyleProperty = DependencyProperty.Register(
"ComboBoxStyle", typeof(Style), typeof(TimePicker));
public Style ComboBoxStyle
{
get { return (Style)GetValue(ComboBoxStyleProperty); }
set { SetValue(ComboBoxStyleProperty, value); }
}
private BindingBase GetTimePickerBinding(DependencyProperty property)
{
return new Binding(property.Name)
{
Source = this
};
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
var comboBox = GetTemplateChild("PART_FirstCombo") as ComboBox;
if (comboBox != null)
{
comboBox.SetBinding(FrameworkElement.StyleProperty,
GetTimePickerBinding(ComboBoxStyleProperty));
}
}
You could then set the combo-box style each time you used the control:
<uc1:TimePicker
ComboBoxStyle="{StaticResource TimePickerComboStyle}"
/>
Or in a global style within the application:
<Style TargetType="{x:Type uc1:TimePicker}">
<Setter Property="ComboBoxStyle" Value="{StaticResource TimePickerComboStyle}" />
</Style>
However, you still wouldn't be able to specify this in a global style from the "shared styles" project unless that project had a reference to the UC project.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Richard Deeming wrote: Or in a global style within the application:
<Style TargetType="{x:Type uc1:TimePicker}">
<Setter Property="ComboBoxStyle" Value="{StaticResource TimePickerComboStyle}" />
</Style>
Ok, I see where you're going with this....
so the App has a ref to both the shared styles project AND the UC project. Once I drop the control onto a form, I could then use the DP to set its style, assuming TimePickerComboStyle is the shared styles project?
If it's not broken, fix it until it is
|
|
|
|
|
Yes, that's right.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
OK, I get it. I never considered having to use a DP, but I'm not opposed to it.
Thanks for your patience.
If it's not broken, fix it until it is
|
|
|
|
|
i have a control, when i rotate it, some corners out of canvas
i would like to avoid this situation
however i try to get position of 4 corners of canvas and control are fail
who can suggest an idea to me ?
|
|
|
|
|
Hi, I have 3 buttons in a user control, I would like to show and hide one button from the Host application or from the user control. Its not working for me. Please check it.
<UserControl x:Class="WPFUserControl.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
xmlns:vis="clr-namespace:WPFUserControl"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.Resources>
<vis:BoolToVisibilityConverter x:Key="BoolToVis" ></vis:BoolToVisibilityConverter>
</UserControl.Resources>
<Grid>
<Button Content="Button1" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75"/>
<Button Content="Button2" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="106,0,0,0"/>
<Button Content="ShowHide" Visibility="{Binding IsShowHideVisible, Converter={StaticResource BoolToVis}, ConverterParameter=False}" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="215,0,0,0"/>
</Grid>
</UserControl>
public partial class UserControl1 : UserControl, INotifyPropertyChanged
{
private bool isShowHideVisible;
public bool IsShowHideVisible
{
get { return isShowHideVisible; }
set
{
if(isShowHideVisible!=value)
{
isShowHideVisible = value;
OnPropertyChanged("IsShowHideVisible");
}
}
}
public UserControl1()
{
InitializeComponent();
}
private void OnPropertyChange(string pPropertyName)
{
if(PropertyChanged!=null)
{
PropertyChanged(this, new PropertyChangedEventArgs(pPropertyName));
}
}
public event PropertyChangedEventHandler PropertyChanged;
}
modified 30-Jun-15 3:32am.
|
|
|
|
|
Since UserControl is a DependencyObjecy , I suspect you'll need to use a dependency property.
You'll also need to set the DataContext to the user control class, so that the binding knows where to find the property.
public partial class UserControl1 : UserControl
{
public static readonly DependencyProperty IsShowHideVisibleProperty = DependencyProperty.Register(
"IsShowHideVisible", typeof(bool), typeof(UserControl1),
new FrameworkPropertyMetaData(false));
public bool IsShowHideVisible
{
get { return (bool)GetValue(IsShowHideVisibleProperty); }
set { SetValue(IsShowHideVisibleProperty, value); }
}
public UserControl1()
{
InitializeComponent();
DataContext = this;
}
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks Richard Deeming, it worked...
|
|
|
|
|
Hi All,
I have one single UserControl library, it has more than 20 of controls. Some of client wants to hide the 2-3 controls. I have to bind the visibility properties of all the controls based on different client types. Which is the best approach to know the which client wants the particular controls.
Thanks
|
|
|
|
|
i want make Online examination system so which module we used help me .and it work flow of the system
|
|
|
|
|
With the demise of Silverlight online and this forum are not compatible, try ASP. You cannot expect a forum to of any use helping you with the minimal information you have supplied.
Look into ASP.net and MVC.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
I have added an expander[^] vertically down the right side of my app. It looks fine like that.
But when I expand it[^], it appears wrong.
This [^]is how it should look.
Here's my XAML:
<Expander Grid.Row="1"
Grid.Column="2"
BorderThickness="1"
BorderBrush="SteelBlue"
Background="White"
ExpandDirection="Left"
IsExpanded="False"
HorizontalAlignment="Right"
MaxWidth="150"
Margin="0,0,5,5">
<pre>
<Expander.Effect>
<DropShadowEffect/>
</Expander.Effect>
<Expander.Header>
<TextBlock Text="My Stuff">
<TextBlock.LayoutTransform>
<RotateTransform Angle="90"/>
</TextBlock.LayoutTransform>
</TextBlock>
</Expander.Header>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<bc:DFTGrid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<bc:DFTComboBox Grid.Column="0"
Style="{StaticResource ComboBoxStyle}"
Margin="2"/>
</bc:DFTGrid>
<bc:DFTListBox Grid.Row="1"
MinWidth="250"
ItemsSource="{Binding Sensors, Mode=TwoWay}"
ScrollViewer.VerticalScrollBarVisibility="Auto">
</bc:DFTListBox>
</Grid>
how do I get the header to go to the top when it's expanded?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
The problem is down to the fact that you have applied a rotation to your Header. It's always going to appear at 90 degrees. You could simply apply a trigger that fires off IsExpanded, and translation at that point.
|
|
|
|
|
I thought the same thing, but removing the rotation simply causes the header text to become horizontal. The header is still down the right side and the content still appears at the top.
See this[^] and this[^].
If it's not broken, fix it until it is
|
|
|
|
|
This is pretty close[^], but there's still a problem:
<Expander Grid.Row="1"
Grid.Column="2"
x:Name="expander"
BorderThickness="1"
BorderBrush="SteelBlue"
Background="White"
ExpandDirection="Down"
IsExpanded="False"
HorizontalAlignment="Right"
Margin="0,0,5,7">
<pre>
<Expander.Effect>
<DropShadowEffect/>
</Expander.Effect>
<Expander.Style>
<Style TargetType="Expander">
<Setter Property="Header" Value="My Stuff"/>
<Style.Triggers>
<Trigger Property="IsExpanded" Value="False">
<Setter Property="Header" Value=""/>
</Trigger>
</Style.Triggers>
</Style>
</Expander.Style>
<Expander.Header>
<TextBlock Text="Sensors">
<TextBlock.Style>
<Style TargetType="TextBlock">
<Style.Triggers>
<DataTrigger Binding="{Binding Path=IsExpanded, RelativeSource={RelativeSource TemplatedParent}}"
Value="False">
<Setter Property="LayoutTransform">
<Setter.Value>
<RotateTransform Angle="90"/>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</Expander.Header>
<f6cc:FalconSensorList Width="150"/>
Now, the when expanded the header is at the top, and the content is below it. So far so good.
However, when NOT expanded, the header text appears horizontal - the rotate isn't working.
https://onedrive.live.com/redir?resid=F6FBCF1880A16630!238&authkey=!ANQDHrjshc7s5AI&v=3&ithint=photo%2cpng
Any idea what's wrong with the transform?
If it's not broken, fix it until it is
|
|
|
|
|
I made some changes to the given xaml code to make it work...
Hope the code snippet will help
<Expander x:Name="MyExpander" BorderThickness="1" BorderBrush="SteelBlue"
Background="White" IsExpanded="False" HorizontalAlignment="Right" MaxWidth="150" Margin="0,0,5,5">
<Expander.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=MyExpander, Path=IsExpanded}" Value="False">
<Setter Property="Expander.ExpandDirection">
<Setter.Value>
Left
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=MyExpander, Path=IsExpanded}" Value="True">
<Setter Property="Expander.ExpandDirection">
<Setter.Value>
Down
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</Expander.Style>
<Expander.Header>
<TextBlock Text="My Stuff">
<TextBlock.Style>
<Style>
<Style.Triggers>
<DataTrigger Binding="{Binding ElementName=MyExpander, Path=IsExpanded}" Value="True">
<Setter Property="TextBlock.LayoutTransform">
<Setter.Value>
<RotateTransform Angle="0"></RotateTransform>
</Setter.Value>
</Setter>
</DataTrigger>
<DataTrigger Binding="{Binding ElementName=MyExpander, Path=IsExpanded}" Value="False">
<Setter Property="TextBlock.LayoutTransform">
<Setter.Value>
<RotateTransform Angle="90"></RotateTransform>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>
</TextBlock.Style>
</TextBlock>
</Expander.Header>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<ComboBox Grid.Column="0"
Margin="2"/>
</Grid>
<ListBox Grid.Row="1"
MinWidth="250"
ItemsSource="{Binding Sensors, Mode=TwoWay}"
ScrollViewer.VerticalScrollBarVisibility="Auto">
</ListBox>
</Grid>
</Expander>
|
|
|
|
|
I have to following in my App.xaml code behind:
public partial class App : Application
{
public App()
{
}
private void Application_Startup(object sender, StartupEventArgs e)
{
Application.Current.DispatcherUnhandledException += dispatchUnhandled;
AppDomain.CurrentDomain.UnhandledException += applicationUnhandledException;
}
private void dispatchUnhandled(object sender, DispatcherUnhandledExceptionEventArgs e)
{
var errorMessage = getInnerException(e.Exception);
displayErrorMessage(errorMessage, e.Exception);
e.Handled = true;
}
private static void applicationUnhandledException(object sender, UnhandledExceptionEventArgs e)
{
var ex = e.ExceptionObject as Exception;
var errorMessage = getInnerException(ex);
displayErrorMessage(errorMessage, ex);
}
private static void displayErrorMessage(string errorMessage, Exception ex)
{
logException(errorMessage, ex);
ErrorHandlerViewModel vm = new ErrorHandlerViewModel();
vm.ErrorMessage = errorMessage;
vm.ErrorText = ex.ToString();
ErrorHandlerView view = new ErrorHandlerView();
view.DataContext = vm;
view.ShowDialog();
Application.Current.Shutdown();
}
private static string getInnerException(Exception e)
{
string msg = e.InnerException == null ? e.Message : getInnerException(e.InnerException);
return msg;
}
private static void logException(string errorMessage, Exception ex)
{
Logger.LogMessage(errorMessage);
Logger.LogMessage(ex.ToString());
}
}
Application_Startup DOES run, but no exceptions are caught. What's wrong here?
Thanks
If it's not broken, fix it until it is
|
|
|
|
|
Are any exceptions thrown? If so, where are they thrown from?
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
yes, I added this in the MainWindowViewModel:
int x = 0;
int y = 10;
int z = y / x;
It throws, it doesn't get caught in the global exception handler.
If it's not broken, fix it until it is
|
|
|
|