|
I want to write declarative code in XAML, not imperative code in C#. But whether provided in XAML or C#, I get the same exception I mention in my initial post, i.e. coding the following in the click event crashes the app:
NavigationService.Source = new Uri("http://www.ParisPhotoTools.com", UriKind.Absolute);
However, the following C# code works in the HyperlinkButton click event handler:
HtmlPage.Window.Navigate(new Uri("http://www.ParisPhotoTools.com", UriKind.Absolute));
Go figure.
|
|
|
|
|
Hi,
I cant figure out how to switch my customcontrols when clicking on a menubar-button.
I have a MainWindow containing the following XAML:
<DockPanel x:Name="MainWindow">
<Menu Name="dropDownMenu"
DockPanel.Dock="Top">
<MenuItem Name="dropDownPage1" Header="File">
<MenuItem Header="Page1" Click="dropDown_Page1"/>
</MenuItem>
<MenuItem Name="dropDownPage2" Header="File">
<MenuItem Header="Page2" Click="dropDown_Page2"/>
</MenuItem>
</Menu>
<Grid Name="gridMainContent" DockPanel.Dock="Top">
<TextBlock>placeholder main content</TextBlock>
</Grid>
<Grid Name="gridStatusBar" DockPanel.Dock="Bottom">
<TextBlock>placeholder statusbar</TextBlock>
</Grid>
</DockPanel>
The task is when clicking on one menubutton i.e. "dropDown_Page1", changing the content of the grid "gridMainContent".
Is there a way to place customcontrols into a grid without code in any *.cs File ? It would be wonderfull if somebody could help me on this.
Cause I´m new to WPF, I welcome you to show me other ways of doing this!
Thx! PingOfDeath
|
|
|
|
|
Include a namespace reference to the assembly containing your custom control, then use your custom control in the XAML. Read up on custom controls and user controls if you don't know what the previous sentence means. You can initially hide it, and then display it when the menu item is selected. Might require some code to handle the command, but you might be able to just accomplish it with an event trigger.
|
|
|
|
|
I would consider using an event handler.
|
|
|
|
|
The OP wanted to avoid ".cs" code (i.e., XAML only).
|
|
|
|
|
There's no way to do it in XAML only without using a markup extension library. This seems like a basic M-V-whatever issue.
|
|
|
|
|
Hi All,
I seem to have an odd problem in VS2008 in Silverlight. It's not showing the correct options, I've just written a 'legal' data template but intellisense isn't actually showing TextBlock in the intellisense popup.
I've got all the latest tools and SDKs installed. Anyone else seen this and solved it?
Cheers,
|
|
|
|
|
Jammer wrote: intellisense popup
Execute Devenv /ResetSkipPkgs on command prompt and try again.Me, I'm dishonest. And a dishonest man you can always trust to be dishonest. Honestly. It's the honest ones you want to watch out for...
|
|
|
|
|
|
Is it possible to add silverlight popup in asp.net code Dre@m is not th@t wh@t u see in sleep.Dre@m is the thing which does not allow u to sleep
|
|
|
|
|
Do you mean you want to access the popup in Silverlight?
This should be possible using Javascript code.Me, I'm dishonest. And a dishonest man you can always trust to be dishonest. Honestly. It's the honest ones you want to watch out for...
|
|
|
|
|
|
Why do you want to add a Silverlight popup inside the Asp.Net page?Regards - Kunal Chowdhury | Software Developer | Chennai | India | My Blog | My Tweets
|
|
|
|
|
There is list box.............
When user will click on that listbox then silverlight
popup should openDre@m is not th@t wh@t u see in sleep.Dre@m is the thing which does not allow u to sleep
|
|
|
|
|
Hi,
I'm gonna pause a Storyboard in WPF, so I've used below code :
Storyboard TheStoryboard;
public window
{
TheStoryboard = (Storyboard)this.FindResource("TheStoryboardName");
}
private void MenuItemPause_Click(object sender, RoutedEventArgs e)
{
TheStoryboard.Pause();
}
But nothing happen!
What is the right way to do that ?
Thanks.
|
|
|
|
|
I think you should get a reference to the actual storyboard that's running. What you may be getting a reference to with the code above is that storyboard class, but not the instantiation that's actually running.
In addition, I would suggest using the keyword "as" to perform the cast. Then check to see if the variable is null. The cast you currently use, if it does not work, will throw an exception. The keyword "as" simply returns null if the cast does not work. Also, look into "TryFindResource" as opposed to "FindResource". I believe it works the same way in that it will return null if the resource is not found. Again, check for null before using it. Both of these suggested changes will make your code, in general, more robust.
Let me know if this helps.
Blitz
|
|
|
|
|
Thanks,
At last I could resolve the problem.
I've written it here[^]
|
|
|
|
|
I have the following:
<dg:DataGrid Visibility="{Binding HideElement, Converter={StaticResource MyBooleanToVisibilityConverter}}"
Grid.Column="1" Cursor="Hand"
Margin="11.5,-21,16,12"
Grid.Row="0" IsEnabled="True"
AlternationCount="2"
Panel.ZIndex="1000"
Style="{DynamicResource DataGridStyle}"
AutoGenerateColumns="False"
SelectedItem="{Binding SelectedPatientDocInfoItem}"
ItemsSource="{Binding PatientDocInfoCollection}"
x:Name="DocumentSearchResultsDG"
BorderThickness="0,0,0,2">
<dg:DataGrid.Columns>
<dg:DataGridTextColumn Binding="{Binding DocumentName}" IsReadOnly="True" Width=".5*" Header="Doc Name" />
<dg:DataGridTemplateColumn IsReadOnly="False" Width=".5*" Header="Delete" Selector.IsSelected="True" >
<dg:DataGridTemplateColumn.CellTemplate >
<DataTemplate >
<Button Command="{Binding DeleteItem, ElementName=DocumentSearchResultsDG}" Panel.ZIndex="7000" Width="45.9" Height="22" >
<Image Source="..\img\delete16.png" />
</Button>
</DataTemplate>
</dg:DataGridTemplateColumn.CellTemplate>
</dg:DataGridTemplateColumn>
</dg:DataGrid.Columns>
</dg:DataGrid>
</Grid>
DeleteItem = new DelegateCommand<object>(obj =>
{
PatientDocumentRepository.Delete(PatientDocument);
PatientDocInfoCollection = new ObservableCollection<PatientDocInfo>();
PatientDocumentCollection.Foreach(x => PatientDocInfoCollection.Add(x));
});
I am following the MVVM pattern so I am trying to delete a row using the button in the DGTemplateColumn but the command is not firing when I click on the button. How do I fire the button without selecting the entire row?
|
|
|
|
|
You are trying to access a public property on the data grid called "DeleteItem". Unless you subclassed the DataGrid, that property will not exist. You probably meant to reference a public property of the Window or Page that your XAML is in.
|
|
|
|
|
Hi
I have the same problem with the button not fireing.
Hav you found a solution to this?
I am using a PresentationModel that exposes a DelegateCommand as my data context to my view. All other bindings work, and if i use a listview the button command binding works but not if im using a datagrid.
my code looks like this:
<UserControl
...
x:Name="MyUserControl"/>
...
<DataGrid AutoGenerateColumns="False" ItemsSource="{Binding MyItems}">
<DataGrid.Columns>
<DataGridColumn Header="MyColumn">
<DataGridColumn.CellTemplate>
<DataTemplate>
<Button Content="Press Me" Command="{Binding ElementName=MyUserControl, Path=DataContext.PressMeIsPressed}" />
</DataTemplate>
</DataGridColumnn.CellTemplate>
</DataGridColumn>
</DataGrid.Columns>
</DataGrid>
|
|
|
|
|
Did you mean to bind to a command in the data context, or did you mean to bind to a command that is a property of the user control?
|
|
|
|
|
Hi
I ment to bind to a public command that my PresentationModel i exposing.
The user controls datacontext is set to this PresentationModel. The binding works fine if I move the button out side the datagrid. Can't figure out why it does'nt work.
/h
|
|
|
|
|
Where the button is located (e.g., in a DataGrid) shouldn't matter. I've created buttons with bound commands inside a DataGrid before without problems. Create a small example that demonstrates the issue and post the full code here (but remember to make the example as small as possible).
|
|
|
|
|
Ok, so i have created a small project that displayes my issue, but i can't upload the whole project as zip, so i have to add all the code:
It is a normal wpf project (.NET 4, but 3.5 should work as well, just need wpf toolkit)
Also i use delegate commands fron WPF PRISM so these two assemblies are needed:
Microsoft.Practices.Composite.dll
Microsoft.Practices.Composite.Presentation.dll
MainWindow.xaml
<Window x:Class="DataGridButtonCommandTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="300" Width="400" x:Name="MyView">
<Grid DataContext="{Binding}">
<Grid.RowDefinitions>
<RowDefinition Height="224*" />
<RowDefinition Height="45" />
</Grid.RowDefinitions>
<DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Path=MyItems}" Margin="10,10,10,0" CanUserAddRows="False" CanUserDeleteRows="False" Grid.RowSpan="1">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Title" Width="100">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Text="{Binding ItemTitle}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTemplateColumn Header="Button" Width="100">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Content="{Binding ButtonTitle}" Command="{Binding ElementName=MyView, Path=DataContext.ShowMyPopUp}"/>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
<StackPanel Orientation="Horizontal" Grid.Row="1" VerticalAlignment="Bottom" Margin="10">
<TextBlock Text="Button with same command binding: " VerticalAlignment="Center" Margin="0,0,5,0"/>
<Button Content="Show popup" Command="{Binding ElementName=MyView, Path=DataContext.ShowMyPopUp}" Width="75"/>
</StackPanel>
</Grid>
</Window>
MainWindow.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.Navigation;
using System.Windows.Shapes;
namespace DataGridButtonCommandTest
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
this.DataContext = new PresentationModel();
}
}
}
PresentationModel.cs
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using Microsoft.Practices.Composite.Presentation.Commands;
namespace DataGridButtonCommandTest
{
public class PresentationModel : INotifyPropertyChanged
{
private ObservableCollection<MyItem> myItems;
public event PropertyChangedEventHandler PropertyChanged;
public DelegateCommand<object> ShowMyPopUp { get; private set; }
public PresentationModel()
{
MyItems = new ObservableCollection<MyItem>
{
new MyItem{ItemTitle = "First", ButtonTitle = "Show popup"},
new MyItem{ItemTitle = "Second", ButtonTitle = "Show popup"},
new MyItem{ItemTitle = "Third", ButtonTitle = "Show popup"}
};
ShowMyPopUp = new DelegateCommand<object>(OnShowMyPopUp);
}
private void OnShowMyPopUp(object obj)
{
var popUp = new PopUpWindow();
popUp.ShowDialog();
}
public ObservableCollection<MyItem> MyItems
{
get
{
return myItems;
}
set
{
if(!Equals(myItems, value))
{
myItems = value;
OnPropertyChanged("MyItems");
}
}
}
private void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
public class MyItem
{
public string ItemTitle { get; set; }
public string ButtonTitle { get; set; }
}
}
PopUpWindow.xaml
<Window x:Class="DataGridButtonCommandTest.PopUpWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="PopUpWindow" Height="300" Width="300">
<Grid>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Text="It works!!!"/>
</Grid>
</Window>
PopUpWindow.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 DataGridButtonCommandTest
{
public partial class PopUpWindow : Window
{
public PopUpWindow()
{
InitializeComponent();
}
}
} modified on Thursday, February 18, 2010 5:10 AM
|
|
|
|
|
You need to HTML encode your code when you paste it. I can't read this.
|
|
|
|
|
hehe, sorry, forgot =)
i fixed it in the previous post
|
|
|
|
|
It's still not quite right. Your observable collection appears to not have a templated type. And I'm not sure that I saw "System.Collections.ObjectModel" included (for ObservableCollection).
|
|
|
|