This code is being run when a button is clicked on my page:
protected void btnExportToPdfButton_click(object sender, EventArgs e)
{
this.ProjectListGrid.ExportSettings.ExportOnlyData = true;
this.ProjectListGrid.ExportSettings.Pdf.PageLeftMargin = Unit.Parse(".2in");
this.ProjectListGrid.ExportSettings.Pdf.PageRightMargin = Unit.Parse(".2in");
ApplyStylesToPdfExport(this.ProjectListGrid.MasterTableView);
this.ProjectListGrid.MasterTableView.ExportToPdf();
}
public void ApplyStylesToPdfExport(GridTableView tableView)
{
// Get access to the header in the grid
GridItem headerItem = tableView.GetItems(GridItemType.Header)[0];
// Apply CSS Styles to the header
headerItem.Style["font-size"] = "8pt";
headerItem.Style["background-color"] = "#777";
headerItem.Style["color"] = "white";
// Apply CSS Styles to each cell in the header
foreach (TableCell cell in headerItem.Cells)
{
cell.Style["color"] = "red";
}
}
The pdf exports, just with no custom styles applied at all.
I have absolutely no idea what I am doing wrong.
For some reason, the control seems to rebind itself and thus it wipes out your inline styles. Possible cause for this behavior is that you set ExportSettings.IgnorePaging to true in your markup. If this is not the case, and if you still have this problem, post your code here so that I can examine it.
Related
I have a grid contains a set of button. I have set the columnSpacing of the grid to 0 but still have the margin between buttons. I assumed its the button control. Even if I put the margin on button to 0, the result is the same.
I can't use boxView, i need a text and clickable on it.
Old thread, but I was getting this on my Android platform. Upgrading Xamarin.Forms from 2.5 to recently released 3.1 seems to have resolved it.
The problem is, android button has default background drawable that has margin. You can remove it using custom renderer. Xamarin.Forms custom renderer
Example:
using System;
using test.Droid;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
[assembly: ExportRenderer(typeof(Button), typeof(DefaultButtonRenderer))]
namespace test.Droid
{
public class DefaultButtonRenderer: ButtonRenderer
{
protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
{
base.OnElementChanged(e);
// Control is Android.Widget.Button, Element is Xamarin.Forms.Button
if (Control != null && Element != null)
{
// remove default background image
Control.Background = null;
// set background color
Control.SetBackgroundColor(Element.BackgroundColor.ToAndroid());
}
}
protected override void OnElementPropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
base.OnElementPropertyChanged(sender, e);
if (e.PropertyName == "BackgroundColor")
{
// You have to set background color here again, because the background color can be changed later.
Control.SetBackgroundColor(Element.BackgroundColor.ToAndroid());
}
}
}
}
This code will remove button click effect. If you want to remain the effect, you have to set Control.Background to proper resource. (ex: Android.Resource.Attribute.SelectableItemBackground)
Alternatively, you can use label with TapGestureRecognizer. You can add TapGestureRecognizer to any view.
I have a asp:Repeater that has a DataSourceID to a custom collection.
The collection class has properties that I would like to display in the FooterTemplate. Because it calculate a value based on all the items.
In the FooterTemplate, is there a way to access the actual collection object? Maybe with Container or Eval.
I don't have direct access to the DataSource. I could change the code to have it as a parameter but would rather find an other way.
can you use something like this?
rpt.DataSource = mydatasource;
rpt.DataBind();
// label in footer
var lblDateTime = rpt.FindControl("lblDateTime") as Label;
if (lblDateTime != null)
{
lblDateTime.Text = mydatasource.First().DateChecked;
}
or like this
void R1_ItemDataBound(Object Sender, RepeaterItemEventArgs e)
{
// Execute the following logic for Footer only.
if (e.Item.ItemType == ListItemType.Footer) {
// put code here to get what you want and show it in the footer
}
}
I have a requirement in my program that the object bound (from ViewModel) in a Combobox is updated as soon as an item is selected in the combobox. Currently, the object only updates once the edit is committed by either pressing Enter or leaving the cell. The user does not want the extra step.
My thought would be to have the act of selecting an item in the combobox trigger the CommitEdit() method and then CancelEdit(). However, I cannot seem to find a way to hook into the SelectionChanged event for the DataGridComboBoxColumn as it is not available.
Other suggestions have been to listen in the viewmodel for a property change event but the property is not changed until the Cell Edit is finished.
Can anyone think of a way to cause the selection of a new item (index) in a DataGridCombobox to close the edit of the cell as if the user pressed Enter or left the cell?
NOTE: I cannot use .NET 4.5 due to customer limitations.
I've had similar issue but i just found out the solution using attached property, This may not exactly fix your problem but it will help in datagrid selection changed issue.
Below is the attached property and handler methods
public static readonly DependencyProperty ComboBoxSelectionChangedProperty = DependencyProperty.RegisterAttached("ComboBoxSelectionChangedCommand",
typeof(ICommand),
typeof(SpDataGrid),
new PropertyMetadata(new PropertyChangedCallback(AttachOrRemoveDataGridEvent)));
public static void AttachOrRemoveDataGridEvent(DependencyObject obj, DependencyPropertyChangedEventArgs args)
{
DataGrid dataGrid = obj as DataGrid;
if (dataGrid != null)
{
if (args.Property == ComboBoxSelectionChangedProperty)
{
dataGrid.SelectionChanged += OnComboBoxSelectionChanged;
}
}
else if (args.OldValue != null && args.NewValue == null)
{ if (args.Property == ComboBoxSelectionChangedProperty)
{
dataGrid.SelectionChanged -= OnComboBoxSelectionChanged;
}
}
}
private static void OnComboBoxSelectionChanged(object sender, SelectionChangedEventArgs args)
{
DependencyObject obj = sender as DependencyObject;
ICommand cmd = (ICommand)obj.GetValue(ComboBoxSelectionChangedProperty);
DataGrid grid = sender as DataGrid;
if (args.OriginalSource is ComboBox)
{
if (grid.CurrentCell.Item != DependencyProperty.UnsetValue)
{
//grid.CommitEdit(DataGridEditingUnit.Row, true);
ExecuteCommand(cmd, grid.CurrentCell.Item);
}
}
}
SpDataGrid is the custom control that i inherited from data grid.
I added below style in generic.xaml as i use the resourcedictionary for style (you can certainly add inside the datagrid).
<Style TargetType="{x:Type Custom:SpDataGrid}">
<Setter Property="Custom:SpDataGrid.ComboBoxSelectionChangedCommand" Value="{Binding ComboBoxSelectionChanged}"/>
</Style>
ComboBoxSelectionChanged is the command in my viewmodel. OnComboBoxSelectionChanged i commented the commitedit because in my case the values were already updated.
Let me know if anything is not clear or any questions. Hope this helps.
I basically want to make things easier by just looping LinkButtons instead of making textfields because the linkbuttons have the rollovers already programmed.
But I have a lot of text and it just keeps going. I want it to wrap like I can do with textfields.
Thanks
package {
import mx.controls.LinkButton;
import flash.text.TextLineMetrics;
public class multiLineLinkButton extends LinkButton {
override protected function createChildren():void {
super.createChildren();
if (textField){
textField.wordWrap = true;
textField.multiline = true;
}
}
override public function measureText(s:String):TextLineMetrics {
textField.text = s;
var lineMetrics:TextLineMetrics = textField.getLineMetrics(0);
lineMetrics.width = 700;
lineMetrics.height = textField.textHeight;
return lineMetrics;
}
}
}
This is the component, but like I said everything is automatically centered.
I've tried paddingLEFT =0; and trying to setStyle("paddingLEFT", 0); but those methods don't work.
var test:multiLineLinkButton = new multiLineLinkButton();
test.label = "sdfdsfdsfdsfsdfsdfsdfdsfsdfdsfdsdsfdsfdsfdffsdfdsfdfdsfdsfdsfdsfdsfdsfsdfdsfdfdsfdfdsfdsfsdfsdfsdf";
test.setStyle("textAlign","left");
var metrics:TextLineMetrics = measureText(test.label);
trace(metrics.height);
myCanvas.addChild(test);
so metrics.height is giving me a height of 14, which i believe is a single line even though it wraps.
This guy did it:
http://ooine.com/index.php/2009/10/12/flex-linkbutton-word-wrap/
FYI, this was the first hit on Google for the search term "flex linkButton word wrap"
I have a scrolling div with Three linkbuttons and three differents divs. I need to apply CSS to active linkbutton as soon as button is clicked.The codes used by me are:
protected void btnNetwork_Click(object sender, EventArgs e)
{
this.btnForecast.CssClass = "li_1";
this.btnBlog.CssClass = "li_2";
this.btnNetwork.CssClass = "li_3_active";
this.btnNetwork.ForeColor = System.Drawing.Color.White;
lblMsg.Visible = false;
BindGW("-----------------------------------");
Forecast.Visible = false;
Blog.Visible = false;
Network.Visible = true;
}
Thanks & Regards,
Khushi
Instead of using server side event use client side javascript event. Try:
$get('btnId').setAttribute("class", "some_class_name");
You will not be able to dynamically change the CSS properties of elements by using post-back, which refreshes the page. Javascript must be used if you want to the change to happen immediately.
Simple example:
take one button and one label
create one stylesheet and add class style1 as:
body
{
}
.style1
{
color: #000080;
}
write this simple code in button click event
protected void Button1_Click(object sender, EventArgs e)
{
this.Label1.CssClass = "style1";
}