|
Put that XAML in the TabControl if it's in XAML or add an item in the constructor perhaps?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I'm trying to make a tab with a close button (a la Firefox and pretty much everything else that uses tabs), and was trying to follow this tutorial:
How to add a Close button to a WPF TabItem[^]
Unfortnately, it doesn't seem to work. The problem appears to be that in the ClosableHeader class there is a button, defined in the xaml, with
Name="button_close" It's then referenced in the C# code for the ClosableTab class as follows:
CloseableHeader closableTabHeader = new CloseableHeader();
this.Header = closableTabHeader;
closableTabHeader.button_close.MouseEnter += new MouseEventHandler(button_close_MouseEnter);
closableTabHeader.button_close.MouseLeave += new MouseEventHandler(button_close_MouseLeave);
closableTabHeader.button_close.Click += new RoutedEventHandler(button_close_Click);
closableTabHeader.label_TabTitle.SizeChanged += new sizeChangedEventHandler(label_TabTitle_SizeChanged);
This generates compile-time errors for every line that contains the text
closableTabHeader.button_close with the message "'WGPM.Views.CloseableHeader' does not contain a definition for 'button_close' and no extension method 'button_close' accepting a first argument of type 'WGPM.Views.CloseableHeader' could be found (are you missing a using directive or an assembly reference?)" (WGPM.Views is the namespace I'm using).
What am I missing? Can I not just refer to a named control like that?
Thanks,
Juliean.
|
|
|
|
|
Sounds to me like either your XAML or code behind class is in the wrong namespace. They have to be in the same namespace to access stuff the way you are trying to.
|
|
|
|
|
Wouldn't that cause an error on the line where the CloseableHeader is created? If it was in a different namespace, I'd get a compile error at that time, wouldn't I? The CloseableHeader gets created correctly, and the assignment of it to the ClosableTab works, but the reference to button_close and label_TabTitle doesn't.
|
|
|
|
|
Not necessarily. The names such as "button_close" and "label_TabTitle" are actually defined in a compiler generated partial class thats not shown in Visual Studio. So the class itself might be in your scope, but the stuff inside it may not be.
Post more of your XAML and .cs class so we can take a look.
|
|
|
|
|
Look in the generated code (CloseableHeader.g.cs)....is the button_close member defined there? And if so, what is its access modifier?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Ok, I'm missing something here. I don't have a CloseableHeaders.g.cs file. All I have is CloseableHeader.xaml and CloseableHeader.xaml.cs
I'm posting the listings of the xaml and the two .cs files (is there a way to add an attachment on this forum?), but they are just copied from the tutorial with virtually no changes.
I'm starting to lean towards this being a namespace issue, as I want the namespace to be WGPM.Views, but as far as directory structure it's in WGPM\Views\BaseClasses
I'm using VS10, .Net 4.0, Win7/64.
CloseableHeader.xaml:
<UserControl x:Class="CloseableHeader"
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"
d:DesignHeight="23" d:DesignWidth="81" Margin="0"
xmlns:local="clr-namespace:WGPM.Views">
<Grid>
<Button Content="X" Height="19" HorizontalAlignment="Right" Margin="0,3,4,0" Name="button_close" VerticalAlignment="Top" Width="20" FontFamily="Courier" FontWeight="Bold" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" FontStretch="Normal" Visibility="Visible" FontSize="14" Padding="0" ToolTip="Close"/>
<Label Content="TabItem" Height="23" HorizontalAlignment="Left" Margin="4,1,0,0" Name="label_TabTitle" VerticalAlignment="Top" FontFamily="Courier" FontSize="12" />
</Grid>
</UserControl>
CloseableHeader.xamls.cs:
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
namespace WGPM.Views
{
public partial class CloseableHeader : UserControl
{
public CloseableHeader()
{
InitializeComponent();
}
}
}
ClosableTab.cs
using System;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
namespace WGPM.Views
{
class ClosableTab : TabItem
{
public ClosableTab()
{
CloseableHeader closableTabHeader = new CloseableHeader();
this.Header = closableTabHeader;
closableTabHeader.button_close.MouseEnter += new MouseEventHandler(button_close_MouseEnter);
closableTabHeader.button_close.MouseLeave += new MouseEventHandler(button_close_MouseLeave);
closableTabHeader.button_close.Click += new RoutedEventHandler(button_close_Click);
closableTabHeader.label_TabTitle.SizeChanged += new SizeChangedEventHandler(label_TabTitle_SizeChanged);
}
public string Title
{
set
{
((CloseableHeader)this.Header).label_TabTitle.Content = value;
}
}
protected override void OnSelected(RoutedEventArgs e)
{
base.OnSelected(e);
((CloseableHeader)this.Header).button_close.Visibility = Visibility.Visible;
}
protected override void OnUnselected(RoutedEventArgs e)
{
base.OnUnselected(e);
((CloseableHeader)this.Header).button_close.Visibility = Visibility.Hidden;
}
protected override void OnMouseEnter(MouseEventArgs e)
{
base.OnMouseEnter(e);
((CloseableHeader)this.Header).button_close.Visibility = Visibility.Visible;
}
protected override void OnMouseLeave(MouseEventArgs e)
{
base.OnMouseLeave(e);
if (!this.IsSelected)
{
((CloseableHeader)this.Header).button_close.Visibility = Visibility.Hidden;
}
}
void button_close_MouseEnter(object sender, MouseEventArgs e)
{
((CloseableHeader)this.Header).button_close.Foreground = Brushes.Red;
}
void button_close_MouseLeave(object sender, MouseEventArgs e)
{
((CloseableHeader)this.Header).button_close.Foreground = Brushes.Black;
}
void button_close_Click(object sender, RoutedEventArgs e)
{
((TabControl)this.Parent).Items.Remove(this);
}
void label_TabTitle_SizeChanged(object sender, SizeChangedEventArgs e)
{
((CloseableHeader)this.Header).button_close.Margin = new Thickness(((CloseableHeader)this.Header).label_TabTitle.ActualWidth + 5, 3, 4, 0);
}
}
}
|
|
|
|
|
jgalak wrote: I don't have a CloseableHeaders.g.cs file
If that's the case then no, it's not going to work because the members are truly not part of the class.
Right-click on the "InitializeComponent()" in your CloseableHeader.xaml.cs file....choose "Go to definition".That should bring you to the generated file (CloseableHeaders.g.cs) - the other half of your partial usercontrol class. Does it?
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Mark Salsbery wrote:
Right-click on the "InitializeComponent()" in your CloseableHeader.xaml.cs file....choose "Go to definition".That should bring you to the generated file (CloseableHeaders.g.cs) - the other half of your partial usercontrol class. Does it?
No, it doesn't. In fact, that's one of the compile errors that comes up.
Is there a way to force it to create the generated file?
|
|
|
|
|
Just create a new usercontrol by adding one to your project. Then copy the code into your new xamlcs files.
Or if you have the source code from the article then the g.cs file should be in there.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
You are missing the obvious Mark. Its a namespace issue just as I originally said 2 days ago, but OP chose to ignore my advice . He is missing the namespace in his x:class.
|
|
|
|
|
Well I figure if he just adds a usercontrol to the project the namespace will be fixed
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Jeez man... why didn't you just listen to me? ... your problem is EXACTLY what I told you. Your class is WGPM.Views.ClosableTab, but your XAML is just ClosableTab. Fix your x:Class to be WGPM.Views.ClosableTab and all will be right with the world.
|
|
|
|
|
SledgeHammer01 wrote: Jeez man... why didn't you just listen to me?
Mostly, because I didn't understand how the namespace was specified in xaml. I thought that xmlns:local="clr-namespace:WGPM.Views" took care of it.
Your suggestion worked perfectly - changing the x:Class line fixed all of the build errors.
Thank you,
Juliean.
|
|
|
|
|
Hi,
I am going to create one windows application using C# + WPF + MVVM + prism 4.
But be-four start to working, i want to know few think about C#,WPF,MVVM and prism 4.
1. Which is Good Project Solution Structure for C# + WPF + MVVC + prism 4. Can give some reference for this.
2. Which is Good way to create Project Solution Structure.
3. Which is Good Way for Exception Handling
4. If any one know LinQ, is LinQ suitable with WPF + MVVC + prism 4. Any LinQ extended library which help for development.
5. Any Existing or 3'rd party library which help for development like Microsoft Enterprise Library
6. Any suggestions for different Tool,Framework,Design Patterns. ...etc
7. Any Reference/Help site links
I know this Discussion is quite big, let us know if want to create diff. discussion for each point.
Thanks In Advance
|
|
|
|
|
1. Depends on what kind of program you're writing
2. See #1
3. See #1
4. See #1
5. See #1
6. See #1
Your choices of tools and design methodologies should always depend on what you're trying to accomplish. The team developing Diablo 3 isn't going to use WPF and MEF, and a group developing an internal accounting system isn't going to be writing DirectX code... Different tools for different tasks.
|
|
|
|
|
Thanks Ian Shlasko,
Application is very simple stock management and accounting system ,
But problem is i am little but new in WPF + MVVM + Prism, so want to some guideline from u about this.
Any Link any think that help me.
|
|
|
|
|
Try this[^] out.
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
|
|
|
|
|
Given your questions I would suggest this is a very bad choice. Use the tools and languages that you understand and are comfortable with. Writing a major application in a language that you are new to is a recipe for disaster at worst, and severe pain at best.
If you just want to learn WPF then there are lots of beginner articles here on CodeProject; here[^] is a really good starting point.
The best things in life are not things.
|
|
|
|
|
Scrolling in nested Listbox
Hi Friends
Hope you all are doing good.
I have few questions about WPF List BOX
Some Background:
We are trying to build a scheduling control like outlook with some custom functionality.
I have already gone through the similar post in Code Project but we tend to take slightly different approach (trying to use MVVM approach).
Problem:
Currently we have a Listbox with 3 items. Each item in the list box is another Listbox with borders as sub items. For E.g. the XAML code looks like this.
<Grid Height="500" Width="500">
<ListBox Name="MasterListBox" HorizontalAlignment="Stretch">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBoxItem >
<ListBox Name="Child1" Height="240">
<ListBoxItem >
<Border Width="200" Background="Red" Height="40"></Border>
</ListBoxItem>
<ListBoxItem >
<Border Width="200" Background="Blue" Height="40"></Border>
</ListBoxItem>
<ListBoxItem >
<Border Width="200" Background="Green" Height="40"></Border>
</ListBoxItem>
</ListBox>
</ListBoxItem>
<ListBoxItem >
<ListBox Name="Child2" Height="240">
<ListBoxItem >
<Border Width="200" Background="Yellow" Height="40"></Border>
</ListBoxItem>
<ListBoxItem >
<Border Width="200" Background="Green" Height="40"></Border>
</ListBoxItem>
<ListBoxItem >
<Border Width="200" Background="Pink" Height="40"></Border>
</ListBoxItem>
</ListBox>
</ListBoxItem>
<ListBoxItem >
<ListBox Name="Child3" Height="240">
<ListBoxItem >
<Border Width="200" Background="Aqua" Height="40"></Border>
</ListBoxItem>
<ListBoxItem >
<Border Width="200" Background="Beige" Height="40"></Border>
</ListBoxItem>
<ListBoxItem >
<Border Width="200" Background="Brown" Height="40"></Border>
</ListBoxItem>
</ListBox>
</ListBoxItem>
</ListBox>
</Grid>
The problem is when I click on the 1st item(Child1) of the MasterListBox in the white area and drag right, the MasterListBox list box scroll to right, But when I click on the subitem (for e.g. say red border) and drag right the MasterListBox doesn’t scroll right.
I am aware that I am trying to drag the item of the inner list box and that’s the reason the outer list box is not scrolling, But it there a way we can override this. I want to select the inner item also so cannot set IsHitTestVisible="False" for inner item.
Thanks you for looking into this. Your help is greatly appreciated.
Regards
Saurabh
modified on Friday, July 22, 2011 7:37 AM
|
|
|
|
|
I would replace the inner listbox with an ItemsControl.
Don't be overcome by evil, but overcome evil with good
|
|
|
|
|
Hi all,
My application is just fine and could work like it is now.
It would be nice to have a kind of "Wait Window" with a progress bar (optional).
So I did the following, and the wait window is showing and closing when I want it:
wndSave oWindow = null;
void oOrg_Save(object sender, SaveEventArgs e)
{
this.isEnabled = false;
this.Dispatcher.Invoke(new DispatcherOperationCallBack((param)=>
{
oWindow = new wndSave();
...
System.Threading.Thread oThread = new Thread(updWindow);
oThread.Start();
wndSave.ShowDialog();
return null;
}), DispatcherPriority.BackGround, new object[] { null });
}
void updWindow()
{
oWindow.Dispatcher.Invoke(new DispatcherOperationCallBack((param)=>
{
foreach(myModel oModel in myView.Models)
{
System.Threading.ParameterizedThreadStart oStart = new ParameterizedThreadStart(mySave);
System.Threading.Thread oNewThread = new Thread(oStart);
oNewThread.Start(oModel);
Action showMethod = new delegate()
{
oWindow.UpdateProgress();
}
}
return null;
}), DispatcherPriority.BackGround, new object[] { null });
}
void mySave(object State)
{
myModel oModel = (MyModel)State;
myModel.Save();
}
If anybody has a trick how to refresh the progressbar would be nice. It is not necessary to be able to move the window, but it would be nice also. Don't know if it is a XBAP problem.
Thank you very much.
|
|
|
|
|
I just solved it by myself:
I had to remove the dispatcher and use an Action<t> instead. That did the job
|
|
|
|
|
Hi folks!
Is it possible to define the targettype of a style to be an interface or an abstract class.
Something like this (in pseudo code)
Style s = new Style();
s.TargetType = class where inherit from baseclass
or
Style s = new Style();
s.TargetType = class which implements given interface
This is needed for creating a generic dragdrop element, where the items in the source can be derived classes.
e.g:
abstract class DDItem<T,Q>
{
public T Identifier {get;set;}
public Q DisplayableContent {get;set;}
}
<ListBox>
<ListBox.Ressources>
<Style TargetType={x:Type local:DDItem}>
<EventSetter Event="MouseLeftButtonDown" Handler="Drag"/>
</Style>
</ListBox.Ressources>
</ListBox>
Would be fine to do this in plain c# as well.
Help would be appreciated!
|
|
|
|
|
Why don't you try inheriting the Style itself?
Silverlight 5 Tutorials : 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
|
|
|
|